Multiple Inheritance : Class Inheritance « Class « Python






Multiple Inheritance

 

class A :
    def __init__(self) :
        self.a = 1

    def print_me(self) :
        print "A: " + str(self.a)

class B :
    def __init__(self) :
        self.b = 2

    def print_me(self) :
       print "B: " + str(self.b)

class C :
    def __init__(self) :
        self.c = 3

    def print_me(self) :
        print "C: " + str(self.c)


class D(A,B,C) :
    def __init__(self) :
        A.__init__(self)
        B.__init__(self)
        C.__init__(self)
        self.d = 4

    def printme(self) :
      A.print_me(self)
      B.print_me(self)
      C.print_me(self)
      print "D: "+str(self.d)

d = D()
d.print_me()

d = D()
d.print_me()

   
  








Related examples in the same category

1.Use __class__, __bases__ and __dict__ for sub and super classUse __class__, __bases__ and __dict__ for sub and super class
2.Print out class treePrint out class tree
3.Class inheritedClass inherited
4.Inherited methodInherited method
5.Polymorphism: override the function from base class
6.Definition and test function for class Circle which is based on Point class
7.Derived class inheriting from a base class.
8.inheriting from multiple superclasses
9.Use Inheritance to add more features to a class
10.class extending dict type
11.Class inheritance: inherit member variable override functionClass inheritance: inherit member variable override function