0
Can you please explain about 'this' and 'super' keywords?
with the help of an example
2 Answers
+ 5
this keyword refers to the current object against which method has been invoked. It is preferably used inside method or constructor of class its data members within the method definition exclusively.
Example
class Point{
private int x;
private int y;
public void setPoint (int x, int y){
this.x = x;
this.y = y;
}
super refers the the base class which has been inherited into a new class. It is used to call public methods and constructors defined in the super class
class a{
public show(){
System.out.Println("I am super");
}
}
class b extends a {
public show(){
super.show();
System.out.Println("I am junior");
}
}
+ 1
thank you mr.devendar