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

What is Lock Based Protocol and what is its use?

2 Answers   Wipro,


difference between applicationserver and webserver

2 Answers   SolutionNET,


Where we can write Rmi registry in the code, without having to write it at the command prompt?

0 Answers  


Can we have more than one action servlet?

7 Answers   HP,


How we set Bean Id when we are creating web application using SpringMVC and Hibernet Integration

1 Answers  






is servlet,struts are threadsafe or not.please telme correct answer

1 Answers   Microsoft,


Why is main purpose of XML?

5 Answers  


What exceptions are thrown by RMI?

1 Answers  


how we can implement interface in jsp ?

2 Answers   Google,


what is the life cycle of jsp?

1 Answers   HCL, ITC Infotech,


Where does the session Object stores? If 100 users are connecting to the server. How does it recognize which session belongs to which user?

5 Answers   HCL, Mobillo Venture,


whats is mean by tiles in struts

2 Answers   SolutionNET,






Categories