Search More About Above Topic Here

Custom Search

Is it possible to call one constructor from another?

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
}


Custom Search
Related Posts with Thumbnails