Class inheritance: inherit member variable override function : Class Inheritance « Class « Python






Class inheritance: inherit member variable override function

Class inheritance: inherit member variable override function
 

class B:
    a = 23
    b = 45
    def f(self): 
       print "method f in class B"
    def g(self): 
       print "method g in class B"

class C(B):
    b = 67
    c = 89
    d = 123
    def g(self): 
       print "method g in class C"
    def h(self): 
       print "method h in class C"


x = C()
x.d = 77
x.e = 88
x.g()
           
         
  








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.Multiple Inheritance
9.inheriting from multiple superclasses
10.Use Inheritance to add more features to a class
11.class extending dict type