| Class Inheritance | ||||||||||||
| Intro to Class Inheritance | Examples of Class Inheritance | |||||||||||
| Public vs. Private or Protected | Abstract Classes | |||||||||||
| Home | ||||||||||||
| In class inheritance, a new class can be derived or inherited from an existing base or a parent class. The new (or derived or child) class will then inherit all members of the existing parent class. The derived class acts as a subtype of the base class. Objects of the derived class can be assigned to a variable of the parent class using pointers and references. Class hierarchy is a pictorial view of all the sub-classes along with their parent classes.
Class hierarchy is also called an inheritance hierarchy. It shows a complete hierarchy of classes and subclasses that are derived from their parent classes. For example, university community can be divided in to employees, students, and alumni. Employees are again divided in to staff and faculty members. Students are divided in to undergraduate and graduate students. Below is the class hierarchy diagram for university community. Deriving a subclass The derived new class is called a subclass. It inherits the attributes and methods of its base class. It can also have its own attributes and methods in addition to the ones that are inherited from the parent class. The keyword �extends� is used to derive a subclass in JAVA. |
||||||||||||