What is the difference between Super and This Keyword?
Answer Posted / deep
Super and This both are keywords and which has some predefined meaning..
Super - with the help of super, you could call super class constructor, method and member of super class..
This - it's used to avoid instance variable hiding, when local variable and instance variable has same name, then at time of assignment, local variable hides instance variable, so in order to get over this problem, this is used to refer instance variable..
class A {
int x; // instance variable
public void m(int x) {
x = x; // here local variable x hides instance variable
x.. so better use this to refer the instance variable
this.x = x; here this.x refer to instance variable and where another x is local variable
}
this is also used to call current class constructor and it can also used to pass current class constructor or method to another object..
you can also use this to call current class constructor or methods..
Rule: Call to this() must be the first statement in constructor or else it will result in compile time error..
| Is This Answer Correct ? | 0 Yes | 1 No |
Post New Answer View All Answers
Explain ioc concept?
Describe, in general, how java's garbage collector works?
difference between ejb,struts,hibernate,spring and jsp
What are the different class loaders used by jvm?
What is glasgow?
What is the purpose of the wait() method?
Is the infobus client side only?
What is Stream Tokenizer?
Why are some of the class and element names counter-intuitive?
What class is used to create Server side object ?
which type of objects reference will be given to client?
How to determine SGA site?
What is the difference between the ‘font’ and ‘fontmetrics’ class?
How many times may an objects finalize() method be invoked by the garbage collector?
How to deploy Jar, War files in J2EE?