Inheritance
Inheriting instance members and methods
1. A superclass normally contains common features of the entities 2. When we define a subclass as an extension of the superclass the subclass may have its own data member and/or methods TOGETHER with the data members and/or methods from the superclass.
Inheritance concept
1. Inheritance enables an object to inherits data members and methods from the existing object. 2. Allows you to create new classes from existing classes from existing classes New-> subclass/ derived class Existing class -> superclass / base class 3. Inheritance is not limited on ONE level only . A subclass can be superclass to other Subclasses
Inheritance types
1. Single : a subclass derives from a single Superclass 2. Multiple : a subclassderives from more than one superclass
Overloading
If the method in the superclass and the subclass has the same name but different parameter lists .
Overridding
If the subclass give its method the same signature as in the superclass.
Rules of superclasses
Private membersof the superclass are private to the superclass. All its data members are also data members of the subclass. All its methods are also methods for the subclass(unless overridden)
Advantages of inheritance
Save time Code reuse Reduce software complexity
Calling superclass constructor and methods
Super(); Super(len,wei); Super.setDimension(len,wid);
Rules of subclasses
The subclass can directly access the public members of the superclass. The subclass can incluse additional data members and/or methods in its class. The subclass can override the public methods of the superclass.