Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


How are this() and super() used with constructors?

Answers were Sorted based on User's Feedback



How are this() and super() used with constructors?..

Answer / ranganathkini

this() - is used to invoke one constructor from another
constructor.

super() - is used to invoke the super class's constructor
from the subclass's constructor

Is This Answer Correct ?    21 Yes 2 No

How are this() and super() used with constructors?..

Answer / ramanareddy333

this()refers the current constructor and
super() refers the super class constructor

Is This Answer Correct ?    18 Yes 1 No

How are this() and super() used with constructors?..

Answer / ravikiran(aptech mumbai)

this() is used to call constructors wih in same class where
as super() is used to call the constructors of it's super class

Is This Answer Correct ?    16 Yes 3 No

How are this() and super() used with constructors?..

Answer / sunil kishore balla

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

Is This Answer Correct ?    11 Yes 2 No

How are this() and super() used with constructors?..

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 ?    3 Yes 1 No

How are this() and super() used with constructors?..

Answer / sushila sonare

When we create an object, first constructor called. In a
constructor first statement should be either this() or
super(). If we didn't keep anything compiler kept super()
statement so constructor chain will be completed. Control
goes to Object class constructor and object creation will
completed. Suppose this() statement kept in constructor than
current class suitable constructor called and this chain
will be continue until control goes to Object class
constructor.

Is This Answer Correct ?    2 Yes 0 No

How are this() and super() used with constructors?..

Answer / rajesh

this() class refer to current class constructor;

super() refers to base class.

Is This Answer Correct ?    3 Yes 2 No

How are this() and super() used with constructors?..

Answer / ritesh kesharwani

this refer to constructor under whose context the behavior
is called.
and super always used to invoke the argument and no argument
constructor of the super type and if super is used under the
constructors it should be the first argument.

Is This Answer Correct ?    1 Yes 3 No

How are this() and super() used with constructors?..

Answer / bhadresh

this() use to invoke only same class constructor.

super() use to invoke super class constructor.

Is This Answer Correct ?    0 Yes 3 No

Post New Answer

More Core Java Interview Questions

What is difference between static and final?

0 Answers  


What is default exception handling in java?

0 Answers  


What is immutability in java?

0 Answers  


What is the difference between set and list?

5 Answers  


What is an abstract method in java programming?

0 Answers  


You can create a string object as string str = “abc”; why cant a button object be created as button bt = “abc”;? Explain

0 Answers  


Can applet in different page/s communicate with each other?

1 Answers  


how to compile jsp?

4 Answers   Logica CMG,


What do you mean by multithreaded program?

0 Answers  


What is Three tier architecture. Can anyone explain with a Ordinary web application Project? (JSP,Servlets,JAVA,DAO) ?

3 Answers   TCS,


what is recursion in java

0 Answers   Cap Gemini,


Program to print 1 1 2 1 2 3 1 2 3 4 like that

8 Answers   Huawei,


Categories