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 do we need singleton class?

1007


What is scope & storage allocation of global and extern variables? Explain with an example

1044


Is this valid in java ? Can we instantiate interface in java?

988


What are the skills required for core java?

1017


Distinguish between a predicate and a function?

990


When a byte datatype is used?

2218


What are variable names?

982


How do you check if two strings are equal in java?

1012


Where local and global variables are stored?

1085


Implement a stack with push (), pop() and min() in O(1) time.

1114


How many bytes is a unicode character?

1007


What is a condition in java?

1013


What is the difference between normal report & matrix report?

1110


What is collection class in java? List down its methods and interfaces.

968


What is package private scope in java?

951