Você está na página 1de 3

4/5/2017

 As we know we can program using multiple


classes.
 Classes can then inherit the properties and
methods from another class.
Jerelyn Pillay  We may have a super class (parent class) and a
sub class(child class)

Super Class Sub class


A super class ,a.k.a parent class, is the most basic , The sub class, a.k.a child class is a more specialized
generic class. It has the most general properties. class.
This class is a stand alone class. It inherits the properties of the parent class
similar to how a human child inherits the
properties from its parent.

1
4/5/2017

Reserved words  In the following example, the student class


The reserved word, super, is used when a sub class inherits the properties from the person class
wants to inherit from a super class.
extends is used at the end of a class declaration
to indicate that this class inherits from the class
after the extends.

How does a sub class inherit from a Method overriding


super class? Two methods with the same identifiers may run
This is done in the sub classs main constructor. differently.
The new specialized variables and fields are For example, the toString() method in the sub class
instantiated as normal. For the inherited properties will usually run differently to the toString()
the keyword super is used and the variable names method in the super class.
are then inserted.

2
4/5/2017

As we can see, the constructor takes in all the The main Class
variables. The properties that can be inherited are Implementation is now quite easy. All that needs
done so via the super keyword. to be done is to create an object of the class you
desire.
Once this is done, methods from that class, or its
super class may be used.

Você também pode gostar