Python Inheritance
If we have a basic Student class which we want to modify to create a University Student object, we can create a new class that incorporates the methods and variables in the Student class but adds new features such as the name of the University. Student class is referred o as the parent class while University Student class is called the child class. We say that UniversityClass is inheriting from Student class.
The Unified Modeling Language (UML) is a set of diagrams that allows you to represent many types of relationship. One type of UML diagram is called a Class Diagram and is used to represent relationships between classes. An example is shown:
To specify the visibility of a class method use the following prefixes:
+ | Public |
- | Private |
# | Protected |
~ | Package |
The one in the example diagram above means that UniversityStudent inherits from Student. All non-private methods in Student can be directly accessed in UniversityStudent. If the method in UniversityStudent has the same name as that in Student, we call this situation, method overriding.