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


Please Help Members By Posting Answers For Below Questions

What is a modular application? What does module-relative mean?

535


Is infobus easy to use?

592


what is handle?

1840


What is the difference between RMI and Corba?

2246


What is the purpose of the wait() method?

613






How to determine SGA site?

1900


What is Stream Tokenizer?

1723


Which container method is used to cause a container to be laid out and redisplayed?

657


What is a policy?

1760


Explain about RMI Architecture?

602


What are the different methods of identifying an object?

563


How messaging services are done, before release of JMS?

1579


Describe activation process?

2051


AS a developer will u create a data source in connection pool? If so how will u do that, how to access the object from connection pool using IRAD tool?

1622


What event results from the clicking of a button?

688