TypeError: Can't instantiate abstract class Test with abstract methods m1
Case-4:
1) from abc import *
2) class Test:
3) @abstractmethod
4) def m1(self):
5) pass
6)
7) t=Test()
We can create object even class contains abstract method b'z we are not extending ABC class.
Case-5:
1) from abc import *
2) class Test:
3) @abstractmethod
4) def m1(self):
5) print('Hello')
6)
7) t=Test()
8) t.m1()
Output: Hello
Conclusion: If a class contains atleast one abstract method and if we are extending ABC class then
instantiation is not possible.
"abstract class with abstract method instantiation is not possible"
Parent class abstract methods should be implemented in the child classes. otherwise we cannot
instantiate child [Link] we are not creating child class object then we won't get any error.
Case-1:
1) from abc import *
2) class Vehicle(ABC):
3) @abstractmethod
4) def noofwheels(self):
5) pass
6)
7) class Bus(Vehicle): pass
It is valid b'z we are not creating Child class object
nd
DURGASOFT, # 202, 2 Floor, HUDA Maitrivanam, Ameerpet, Hyderabad - 500038,
3 040 – 64 51 27 86, 80 96 96 96 96, 92 46 21 21 43 | [Link]