Thursday, 7 April 2016

How to create super keyword in java



Super keyword:- Super keyword is used for accessing super class methods and variables. And for calling super class constructors.

class A{
void show(int x){
System.out.println("Parent show");
}
}
class Main extends A{
void show(int x){
super.show(20);
System.out.println("Child show");
}
public static void main(String args[]){
Main m=new Main();
m.show(10);
}
}

OUTPUT:-
C:\Users\Satyendra\Desktop>javac main.java
C:\Users\Satyendra\Desktop>java Main
Parent show
Child show

No comments:

Post a Comment