| The Basic of Inheritance : Program description : Here i created a class name student which by default inheriting from the object class , inside this i created a constructor with passing name and age as parameter . defining two methods showName(self) to show the student name and showAge (self) to show the student age . Now One more class is created named teacher which is inheriting from the student class , inside this class a method named showTeacher (self,name) is created which shows the teacher name . Thats all now from the teacher class we can call the methods of the student class (i.e. the Base class) . So here : Base class => student class Derived class => teacher class (this class have all the property of the base class and also it is capable to define its own methods that's the best part of the inheritance) Example Code : class student (object): def __init__(self,name,age): self.name = name self.age = age def showName(self): print self.name def showAge (self): print self.age class teacher(student): def showTeacher(self,name): self.name = name print self.name x = student("dipayan","25") print x x.showName() x.showAge() y = teacher("jobs",50) print y y.showName() y.showAge() y.showTeacher("Sir") |