What is the difference between Super and This Keyword?




Answers were Sorted based on User's Feedback



What is the difference between Super and This Keyword?..

Answer / chandrasekhar

Super is used for refer super class members.this is used for refer same class meembers

Is This Answer Correct ?    2 Yes 0 No

What is the difference between Super and This Keyword?..

Answer / chandrasekhar.p

By using super we can refer the super class methods or members.This is used for refer current class members

Is This Answer Correct ?    2 Yes 1 No

What is the difference between Super and This Keyword?..

Answer / skp

Call to super() should be the first statement in constructor instead of this(), otherwise it will result in compile-time error.

Is This Answer Correct ?    1 Yes 0 No




What is the difference between Super and This Keyword?..

Answer / 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



More Advanced Java Interview Questions

How do you download stubs from a Remote place?

1 Answers  


Why is main purpose of XML?

5 Answers  


What are the types of data passing mechanisams under JMS specification?

1 Answers  


What is UniCastRemoteObject and what is its use in RMI?

6 Answers  


What are JTA/JTS and how they used by client?

0 Answers  






what is difference between object state and behaviour?

3 Answers  


If we opened Windows Internet Explorer 4 times, does it starts 4 processes or 4 threads?

0 Answers  


What are the methods used for inter-thread communication? and in what class these methods are defined?

2 Answers  


the use of try and ffinally keyword

1 Answers  


What is the difference between a stub and a skeleton?

9 Answers   Wipro, Polaris, Qualcomm, ABC, College School Exams Tests, Geoservices, Rajiv Gandhi College of Engineering and Technology RGCET, UTIITSL,


Can a thread be a member of another thread?

2 Answers  


how the action can be map from jsp page to bean class in mvc1

1 Answers   Photon,






Categories