Inheritance And It’s Types Using Python3

1. Single Inheritance Using Python3.


class Base:
    def geta(self):
        return 10
    def getb(self):
        return 20


class Derived(Base):
        def sum(self):
            print(self.geta()+self.getb())



d=Derived()
d.sum()

2. Multilevel Inheritance Using Python3.


class Base:
    def geta(self):
        return 10
    def getb(self):
        return 20

class Derived(Base):
        def sum(self):
            return(self.geta()+self.getb())

class LastDerived(Derived):
        def avg(self):
            print(self.sum()/2)


ld=LastDerived()
ld.avg()

3. Multiple Inheritance Using Python3.


class Base1:
    def geta(self):
        return 10
class Base2:
    def getb(self):
        return 20

class Sum(Base1,Base2):
        def sum(self):
            print(self.geta()+self.getb())


x=Sum()
x.sum()

4. Hierarchical Inheritance Using Python3.

class Base:
    def geta(self):
        return 10
    def getb(self):
        return 20

class Sum(Base):
    def sum(self):
        print (self.geta() + self.getb())

class Sub(Base):
    def sub(self):
        print (self.geta() - self.getb())
f1=Sum()
f1.sum()
f2=Sub()
f2.sub()

5. Hybrid Inheritance Using Python3.

class Base:
    def geta(self):
        return 10
    def getb(self):
        return 20
class Derived1(Base):
    def sum(self):
        return(self.getb()+self.geta())
class Derived2(Base):
    def sub(self):
        return(self.getb()-self.geta())
class LastDerived(Derived1,Derived2):
    def avg(self):
        print(self.sum()+self.sub())
ld=LastDerived()
ld.avg()