
class Person...{
String name;
String hobby;
String wife;
int age;

public Person(String name)...{
this.name = name;
}

public Person(String hobby,String wife)...{
this.hobby = hobby;
this.wife = wife;
}

public Person(int age)...{
//this("张无忌");
this("乾坤大挪移","赵敏");
this.age = age;
}

void shout()...{
System.out.println("Name is " + name);
System.out.println("Hobby is " + hobby);
System.out.println("Wife is " + wife);
System.out.println("Age is " + age);
}

public static void main(String[] args)...{
new Person(26).shout();
}
}
本文介绍了一个使用Java编写的简单Person类实例,该类包含了多个构造器以实现不同参数的初始化,并展示了一个具体的对象创建及属性打印的方法。
1319

被折叠的 条评论
为什么被折叠?



