What You Can Do in a Subclass
by, 04-26-2012 at 06:29 PM (795 Views)
Subclass inherits protected and public members of parent no matter in which package is the subclass. If subclass and parent are in same package then package-private members are also inherited. Inherited members could be used to hide them, replace them or supplement them, with newer members:
- Just the way other fields do, inherited fields can also be directly used.
- A field can be declared in subclass with similar name just like that present in superclass hence hiding it (which isnít recommended)
- New fields can be declared in subclass which are absent in superclass.
- Use inherited methods direcly.
- New instance method could be written in subclass which has similar sign just like that one present in superclass. Hence override it.
- New static method could be written in subclass which has similar sign as that of which is present in superclass. Hence hiding it.
- In the subclass, new methods could be declared which are not there in superclass.
- Subclass constructor could be written to invoke the superclass constructor either by keyword super or implicitly.