How are this and super used?




Answers were Sorted based on User's Feedback



Answer / sucharitha

this() is used to invoke present class constructor.Super()
is used to invoke super class Constructor.

Is This Answer Correct ?    8 Yes 0 No

Answer / niranjanravi

this is used to resolve the naming collision between class
scope var. and method scpoe var.
super is used to the resolve the naming collision between
superclass member and subclass member.

Is This Answer Correct ?    6 Yes 0 No

Answer / ravikiran(aptech mumbai)

this keyword is used to refer the current instance of the
particular class where as super keyword is used to refer the
superclass members.

Is This Answer Correct ?    5 Yes 0 No




Answer / kabita

'this' and super are two keywords in java.
'this' doesn't support inheritance bt 'super' supports
inheritance.
this keyword is used in two cases
1.to differentiate betn instance and local variables.
2.calling of one constructor from another constructor.
Restriction:this keyword should be written in lowercase &
must used in firstline.more than one 'this' keyword is not
used in one block.
super is used 4 three reason.
1.differentiates betn superclass variable & child class
variables.
2.calling of superclass constructor in childclass
constructor.
3.it is also used in calling of superclass override method
in child class.
restriction:
it must be in 1stline.
must be in lowercase.

Is This Answer Correct ?    4 Yes 0 No

Answer / shripal

this() keyword is use to invoke the current class.
while super() keyword is use to invoke super class.

Is This Answer Correct ?    2 Yes 0 No

Answer / sreekar reddy vanguru

Mainly this() is used to avoid hidding the field varaibles
by the varaibles of the methods which are having same name..

super() is used to invoke the super class from sub class...

Is This Answer Correct ?    0 Yes 0 No

Answer / qim2010

this() is used to invoke a constructor of the same class

super() is used to invoke a super class constructor and

Example of using this():
public Pet(int id) {
this.id = id; // “this” means this object
}
public Pet (int id, String type) {
this(id); // calls constructor public Pet(int id)
this.type = type; // ”this” means this object
}

Example of using super():

If a class called “SpecialPet” extends your “Pet” class then
you can
use the keyword “super” to invoke the superclass’s
constructor. E.g.
public SpecialPet(int id) {
super(id); //must be the very first statement in the
constructor.
}

To call a regular method in the super class use:
“super.myMethod( );”. This can be called at any line.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer



More Core Java Interview Questions

java can provide security ,how can provide?

8 Answers   IBM, Genpact, BNP Paribas, Aspire,


What is Yield() method when we r using this ? tell exactly

2 Answers  


what is business delegate?

2 Answers   TCS,


FOR EXAMPLE WE R HAVING TWO LIST ELEMENTS ..BOTH LISTS CONTAINS ID,NAME,PLACE ..I NEED TO COMPARE BOTH IDS IN TWO LISTS,IF ID'S R SAME MEANS WE HAVE ADD THE DETAILS(LIKE NAME,PLACE) TO MAP...HOW IS POSSIBLE ?CAN ANY ONE SUGGEST?

1 Answers  


How OOPS concept is achieved in Java?

6 Answers   Cognizant, JPMorgan Chase,






What is difference between hash mapping and hash table?

5 Answers   Wipro, NDS,


What are the types of statement? explain

1 Answers   SysBiz,


Java violates few objected oriented concepts. Can you explain in what way?

3 Answers   Ness Technologies,


Hi Friends.. can any one provide the real time example for methodoverloading and methodoverriding .........

2 Answers   Honeywell,


What is static and a non-static inner class?

3 Answers  


what is Vector class?

2 Answers  


could you run the java program without main method?

6 Answers  






Categories