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.
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.
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:
Rs. 20,000 US$ 300
Today: Rs. 10,000 US$150
Course Duration: 30 hrs
Posted on: November 17, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles