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

Is hashmap thread safe?

934


What is consumer interface?

945


Can we override constructor?

967


Difference between stack and queue?

1013


What super () does in java?

856


What is a native method in java programming?

1000


How many inner classes can a class have?

992


What does system out println () do?

965


Explain about wait() method?

978


Explain about class in java?

1044


What happens if main method is not static?

949


What is functional interface in java example?

934


What is an abstract class and what is it’s purpose?

906


What is equals method in java?

977


When a byte datatype is used?

2036