Home Tutorials Python OOP Concepts Abstract Method
Abstract Method

Abstract Method


24. Abstract Method

An abstract method declares behavior that subclasses must implement. It defines the required interface without giving the full implementation in the base class.

Syntax

@abstractmethod
def method_name(self):
    pass

Example

from abc import ABC, abstractmethod

class Payment(ABC):
    @abstractmethod
    def pay(self):
        pass

class UPI(Payment):
    def pay(self):
        print("Payment through UPI")

p = UPI()
p.pay()

Output

Payment through UPI
Example

🏋️ Test Yourself With Exercises

Take our quiz on Abstract Method to test your knowledge.

Browse Quizzes »