+ 2
What is the use of this and super keywords in java ?Can anyone explain me with some examples?
2 Antworten
+ 4
"this" refers to the current object that called method
a = new obj();
function obj(){
this.x = 5
}
a.x gives 5
0
super keyword is refer to super class.
How to use it?
- You can use it when you want to call constructor of super class
- You can uses it when you want call a method of super class