浏览量 4694
2014/01/02 02:09
public class BasicContainer {
public static void main(String[] args) {
Person p1 = new Person();//以无参构造器产生实例
Person p2 = new Person("mike",22,1);//以有参构造器形式产生实例
}
}
class Person{
String name;
int age,sex;
public Person() {//无参构造函数
}
public Person(String name, int age, int sex) {//有参构造函数
super();
this.name = name;
this.age = age;
this.sex = sex;
}
}
上一篇 搜索 下一篇