How are this and super used?




Answers were Sorted based on User's Feedback



How are this and super used?..

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

How are this and super used?..

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

How are this and super used?..

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




How are this and super used?..

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

How are this and super used?..

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

How are this and super used?..

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

How are this and super used?..

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

What are null interfaces? Give some examples?

2 Answers  


As a developer what steps do you take to improve the performance?

4 Answers  


what is the use of finalize()Method please explain with an example

3 Answers  


How do you implement polymorphism in our day to day life?

0 Answers   Cap Gemini,


what is auto boxing

3 Answers   UHG,






I have a string like _a01_a02_a03_ and another string like _2_1.5_4_ as input.I want to extract a01,a02... to a string array and 2,1.5,etc to a double array with a01 corresponds to 2 and a02 to 1.5 etc. Need code in core java.. Can you do it?

1 Answers   Cognizant,


What is the difference between Trusted and Untrusted Applet ?

2 Answers   IBM,


what are the rules to use try catch finally?

1 Answers   Satyam, UJ,


when a servlet sends request for first time it uses the follwing methods a)init b)doget() c)dopost() d)service

4 Answers   Accenture,


what are variables in java

7 Answers   Wipro,


Why does java not allow multiple public classes in a java file ?

2 Answers  


The class "Class" is belongs to which package?? a) java.lang b)java.lang.reflect c)java.util d)None

4 Answers  






Categories