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...

Can you call a constructor within a constructor?

Answer Posted / qim2010

Yes, by using this() syntax. E.g.

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
}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

I want to re-reach and use an object once it has been garbage collected. How it's possible?

965


How to instantiate static nested classes in java?

1024


What are the main differences between notify and notifyAll in Java?

1044


What is finalize method?

1054


Why do we need wrapper class?

949


Is boolean a wrapper class in java?

1008


What is the difference between heap and stack memory?

1149


Difference between linkedlist and arraylist.

1027


How many types of constructors are used in java?

1108


How many types of classes are there in java?

1006


What are the rules for naming an array?

999


Explain about static imports in java?

955


What is use of set in java?

940


How do you detect memory leaks?

1014


define polymorphism in java

1049