Thursday, 8 October 2015

"Super" keyword usage example in Java


public class First {

public static void main(String[] args) {
// TODO Auto-generated method stub
Third obj=new Third();
}

}



public class Second {
int i;
Second(int i){
this.i=i;
System.out.println("This is super class param constructor");
}
}



class Third extends Second{
Third(){
super(20);
System.out.println("The value of super calss variable i is " +super.i);
}
}

output:-
This is super class param constructor
The value of super calss variable i is 20

No comments:

Post a Comment