publicclass CreateObject {
intage;
String name;
public CreateObject(String name){
this.name = name;
}
public CreateObject(String name,int age){
this.name = name;
this.age = age;
}
//....
publicstatic CreateObject getInstanceWithName(String name){
returnnew CreateObject(name);
}
publicstatic CreateObject getInstanceWithNameAndAge(String name,int age){
returnnew CreateObject(name, age);
}
publicstaticvoid main(String[]args){
CreateObject createObject = new CreateObject("nnn");
CreateObject createObject2 = new CreateObject("nnn", 11);
CreateObject createObject3 = CreateObject.getInstanceWithName("mmm");
CreateObject createObject4 = CreateObject.getInstanceWithNameAndAge("mmm", 22);
}
}