[go: up one dir, main page]

0% found this document useful (0 votes)
2 views1 page

oops-4-02

The document explains the concept of abstract classes in Python, which are classes that cannot be instantiated directly and require child classes to implement their abstract methods. It provides examples demonstrating the creation of objects from both concrete and abstract classes, highlighting that an abstract class must inherit from the ABC class in the abc module. Additionally, it emphasizes that an abstract class can still be instantiated if it does not contain any abstract methods.

Uploaded by

vishnu050621
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

oops-4-02

The document explains the concept of abstract classes in Python, which are classes that cannot be instantiated directly and require child classes to implement their abstract methods. It provides examples demonstrating the creation of objects from both concrete and abstract classes, highlighting that an abstract class must inherit from the ABC class in the abc module. Additionally, it emphasizes that an abstract class can still be instantiated if it does not contain any abstract methods.

Uploaded by

vishnu050621
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 1

Eg:

1) from abc import *


2) class Fruit:
3) @abstractmethod
4) def taste(self):
5) pass

Child classes are responsible to provide implemention for parent class abstract methods.

Abstract class:
Some times implementation of a class is not complete,such type of partially implementation
classes are called abstract classes. Every abstract class in Python should be derived from ABC class
which is present in abc module.

Case-1:

1) from abc import *


2) class Test:
3) pass
4)
5) t=Test()

In the above code we can create object for Test class b'z it is concrete class and it does not conatin
any abstract method.

Case-2:

1) from abc import *


2) class Test(ABC):
3) pass
4)
5) t=Test()

In the above code we can create object,even it is derived from ABC class,b'z it does not contain
any abstract method.

Case-3:

1) from abc import *


2) class Test(ABC):
3) @abstractmethod
4) def m1(self):
5) pass
6)
7) t=Test()

nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
2  040 – 64 51 27 86, 80 96 96 96 96, 92 46 21 21 43 | www.durgasoft.com

You might also like