Super - keyword

super is a keyword in java that plays an important role in case of inheritance.

Super - keyword

Super - keyword

     

super keyword

super is a keyword in java that plays an important role in case of inheritance. Super keyword is used to access the members of the super class. Java uses this keyword to resolve two purposes. The first purpose is, accessing the hidden data variables of the parent class hidden by the child class.

Lets take an example, Suppose there is a class A that includes two instance variables as  int a and float b. class B extends to class A and contain its own data members having the same name a and b. In this case variables of class B hides the variables of class A, to access to those variables we the super keyword. Accessing of super class variables is done by using the following syntax.

super.member;

Here member can refer to either an instance variable or a method.

Calling super class constructor: Super keyword is also used to call super class constructor in the subclass. This is done by using the following command.

super(param-list);

Here parameter list includes the parameter that the constructor requires in the super class. super is always be be the first statement to be executed inside a super class constructor. Pass the empty parameter list in order to call the default constructor.

To know more about super click at: 

http://www.roseindia.net/java/master-java/inheritance.shtml