Home Tutorials Python OOP Concepts Abstract Class
Abstract Class

Abstract Class


23. Abstract Class

An abstract class is a class that contains one or more abstract methods and is meant to be inherited. It provides a common structure for child classes.

Syntax

class Demo(ABC):
    @abstractmethod
    def show(self):
        pass

Example

from abc import ABC, abstractmethod

class Device(ABC):
    @abstractmethod
    def power_on(self):
        pass

class TV(Device):
    def power_on(self):
        print("TV is ON")

obj = TV()
obj.power_on()

Output

TV is ON
Example

🏋️ Test Yourself With Exercises

Take our quiz on Abstract Class to test your knowledge.

Browse Quizzes »