![]() |
| Click to enlarge |
Showing posts with label inheritance. Show all posts
Showing posts with label inheritance. Show all posts
Friday, May 19, 2017
Instantiating a Python subclass
In this screenshot we instantiate the project manager subclass. The project manager subclass derives from the employee details parent class. Note that there are two cases: one where we input the employee id, name, etc, and the another where we do not supply any arguments to the constructor. In this case the default values in the constructor declaration supply the values.
This concludes our screenshot series for this course. We will be offering it in our studio in the coming weeks.
Thursday, May 18, 2017
Python Subclasses
As with any typical object-oriented language it is possible in Python to create a subclass that inherits properties and methods from a parent or superclass. This is shown in our attached screenshots. The subclass (or child class) can inherit the methods as is or it can override them. This means they are redefined in the subclass. When an object is instantiated from the child class the methods not overridden will work just as they do in the parent class. The overridden methods will work as defined in the subclass.
Our little example shows a project manager subclass created based on the parent employee class. It overrides the salary computation to give a bonus rather than deduct an allowance. It also extends the class by adding a method to return the number of subordinates. Note also the use of the keyword super in the subclass to invoke a method in the superclass.
Our little example shows a project manager subclass created based on the parent employee class. It overrides the salary computation to give a bonus rather than deduct an allowance. It also extends the class by adding a method to return the number of subordinates. Note also the use of the keyword super in the subclass to invoke a method in the superclass.
![]() |
| Click to enlarge view |
Subscribe to:
Posts (Atom)

