Inheritance

Inheritance
   The method of deriving a new class from an old one.

 Class subclass extends superclassname
{ Variable declaration;
    Method declaration;
}

A subclass object can access data members and methods in superclass.

Subclass constructor 
  It is used to construct the instance variables of both the subclass and the superclass.
Super- to invoke the constructor method of the superclass.
Conditions for Super.
Ø Super may only be used within a subclass constructor method.
Ø The call to SuperClass constructor must appear as the first statement within the subclass constructor
Ø The parameters in the super call must match the order and type of the instance variable declared in the super class.

Final- To prevent the subclasses from overriding the members of the super class.
- To prevent a class being further subclasses for security reasons.
Method final ensures that the functionality defined in this method will never by altered in any way.

finalize() -- Alternate to destrcutor -- To free the non-object resources such as file descriptor or window system fonts.

Comments