Java Constructor Overloading -


i'm new java , i'm having trouble understanding constructor issue, have looked @ many tutorials , still i'm having difficult understand why use constructors, anyway, specific question :

correct me if i'm wrong, if want add in class more 1 constructor, i'll write first 1 , second int type (inside brackets).

  1. is because constructors have same name class , need distinguish between them ?

  2. what if want add third constructor ? can int type ?

a) because constructors have same name class , need distinguish between them ?

yes constructors name of class without return type, , in order distinguish between them, can have different parameters.

b) if want add third constructor ? can int type ?

yes, can add no. of overloaded constructors should different in no. and/or type of parameters.

like :-

public user() // default constructor { }  public user(int age) // overloaded constructor int { }  public user(string name) // // overloaded constructor string { }  public user(string name, int age) // // overloaded constructor string , int { } 

Comments