Data Abstraction with Constructors using Inheritance in Python - 3 || Data Abstraction || Python

In this we are going to see a program on Data Abstraction with Constructors using Inheritance in Python - Type 3 in Python Programming Language.


class Shape:
    def area(self):
        pass


class Square(Shape):
    def __init__(self, s):
        self.s = s

    def area(self):
        print(self.s**2)


class Triangle(Shape):
    def __init__(self, l, b):
        self.l = l
        self.b = b

    def area(self):
        print(0.5*self.l*self.b)


s = Square(8)
s.area()

t = Triangle(8, 10)
t.area()

# Coded by Saahil

#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post