Super Keyword Example Java Program


  • Super keyword 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 super keyword.
  • It is also used by class constructors to invoke constructors of its parent class.



Super Keyword Example Program

class Main{  
	int distance=50;  
class SuperKeywordDemo extends Main{  
	int distance=100;  
	void display(){  
		System.out.println("distance is: "+super.distance);
	public static void main(String args[]){  
		SuperKeywordDemo obj=new SuperKeywordDemo();  

Sample Output

distance is: 50