39 abstract method in python

 

'''

1. An abstract method is a method that is declared, but contains no implementation.

2. By defining an abstract base class, 

you can define a common API for a set of subclasses.

3. By using abc module we can define abstract class.

'''

from abc import ABCMeta,abstractmethod


class One(metaclass=ABCMeta):

    @abstractmethod

    def add(self):

        print(' \n ONE ADD ')


    @abstractmethod

    def sub(self):

        pass


#a = One()

#a.add()


## If you inheritence an abstaruact class 

you should impliment that all those methods which are abstract ,methods

class Two(One):

    def add(self):

        print(" \n TWO ADD")


    def sub(self):

        print(' \n TWO SUB')



ins = Two()

ins.add()

ins.sub()



Comments

Popular posts from this blog

1 PYTHON PROGRAMMING

4 Tuple data types

2 String data types