class Person
{
private String name;
private int age;
Person()
{
System.out.println("A:姓名="+name+": 年龄="+age);
}
Person(String n)
{
name = n;
System.out.println("B:姓名="+name+": 年龄="+age);
}
Person(String n,int a)
{
name = n;
age = a;
System.out.println("C:姓名="+name+": 年龄="+age);
}
public void setName(String n)
{
name = n;
}
public String getName()
{
return name;
}
public void setAge(int a)
{
if(a>1 && a<100)
age = a;
}
public int getAge()
{
return age;
}
void show()
{
System.out.println("姓名="+name+": 年龄="+age);
//System.out.println("姓名="+name);
}
}
class PersonDemo2
{
public static void main(String[] args)
{
/*
Person p = new Person();//对象一建立就会调用与之对应的构造函数
p.setName("zhangs");
p.setAge(44);
p.show();
*/
new Person("hfiei",2).show();
//Person p = new Person();
//Person p1 = new Person("jdjkeki");//这里面的赋值是构造函数里面变量的赋值
//Person p2 = new Person("jdjkeki",44);
}
}