Abstract Class in Python

Master Python with 70+ Hands-on Projects and Get Job-ready - Learn Python

Program 1

# Abstract class and methods
from abc import ABC,abstractmethod

# class Button(ABC):
#     @abstractmethod
#     def click(self):
#         None
# class Color(Button):
#      None
#     # def click(self):
#     #     print("Its Red Color now")

# class Image(Button):
#     def click(self):
#         print("Its My Photo now")

# C=Color()
# C.click()        
# I=Image()
# I.click()

class Area(ABC):

    @abstractmethod
    def area(self):
        None
class Circle(Area):
    def area(self):
        r=float(input("Enter Radious of Circle"))
        A=3.14*r*r
        print("Area= ",A)

class Rect(Area):
    def area(self):
        l=float(input("Enter length"))
        b=float(input("Enter bridth"))
        print("Area=",(l*b))


# C=Circle()
# C.area()
R=Rect()
R.area()

 

Your opinion matters
Please write your valuable feedback about DataFlair on Google

courses

DataFlair Team

DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.

Leave a Reply

Your email address will not be published. Required fields are marked *