The this keyword provides a reference to the current object. The super keyword refers to the parent class object. These keywords allow us to refer to a variable or method that has the same name in the current context and in the parent object.
Usage of the this and super keywords
Usage of the this keyword
Here is the most popular example:
class A {
private int count;
public void setCount(int count) {
count = count; // 1
}
public int getCount(){
return count; // 2
}
}
The first line looks ambiguous, but, in fact, it is not: the local variable, int count , hides the private property instance int count. We can demonstrate this by running the following code:
A a = new A();
a.setCount...