What is parent class
Super class and subclass
We can extend a class by create its child class. The process is called inheritance. The class being inherited is called super class.
In the following code we can see that we can indicate a super class using parentheses after the child class name.
class ParentClass: # define a class object
def setdata(self, value): # define class methods
self.data = value # self is the instance
def display(self):
print self.data # self.data: per instance
# from w ww . ja v a 2s . com
class ChildClass(ParentClass): # inherits setdata
def display(self): # changes display
print 'Current value = "%s"' % self.data
z = ChildClass()
z.setdata(42) # setdata found in ParentClass
z.display() # finds overridden method in ChildClass
The code above generates the following result.