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

Why scanner is used in java?

1063


Why is java called java?

1041


How are multiple inheritances done in Java?

1131


how to open and edit XML file in Weblogic???

1965


What is a singleton class? Give a practical example of its usage.

1097


What is meant by design patterns?

1021


What is multithreading in java?

1051


What are variable arguments or varargs?

998


What is void class in java?

966


When should you use arraylist and when should you use linkedlist?

924


What is anti pattern in programming?

964


What are the actions that can occur when a thread enters blocked state?

1054


Can two objects have same hashcode?

993


What does java stand for?

1112


Which is bigger float or double?

968