From Wikibooks, open books for an open world
super is a keyword.
- It is used inside a sub-class method definition to call a method defined in the super class. Private methods of the super-class cannot be called. Only public and protected methods can be called by the
- It is also used by class constructors to invoke constructors of its parent class.
|Code listing 1: SuperClass.java
|Code listing 2: SubClass.java
Running the above program:
|Command for Code listing 2
|Output of Code listing 2
Hello from SuperClass Hello from SubClass
In Java 1.5 and later, the "super" keyword is also used to specify a lower bound on a wildcard type parameter in Generics.
|Code section 1: A lower bound on a wildcard type parameter.