If the 'subclass' has declared the same method that is already available in 'superclass' then the subclass uses 'super' keyword to access the method declared in the 'superclass'.
Example - super.methodname( );
Lets implement this on Eclipse IDE:
1. Create 'Superclass' superclass as shown below:
5. Observe that the output is displayed in the console as shown below:
Click here to download this project containing 'Superclass', 'Subclass' and 'SuperMethodDemo' class files used in this post (You can download this project and import into Eclipse IDE on your machine)
So now we have come to know that 'super' keyword can be used to access the instance variables and methods of the 'superclass' that have hidden by the instance variables and methods of the 'subclass'. We can also use 'super' keyword to call the Superclass constructors.
Please comment below to feedback or ask questions.
How to call the 'Superclass' constructors using the 'super' keyword will be explained in the next post.