public class PersonDemo2 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Person p1 = new Person();
Person p2 = new Person("wangyang");
p2.setName("wangyangyang");
System.out.println(p2.getName());
Person p3 = new Person("wangyang",10);
}
}
class Person //The type Person is already defined 怎么改?什么原因?
{
private int age;
private String name;
{
System.out.println("person code run");
cry();
}
Person()
{
System.out.println("A:name="+name+","+"age="+age);
cry();
}
Person(String n)
{
name = n;
System.out.println("B:name="+name+","+"age="+age);
cry();
}
public void setName(String n)
{
name = n;
}
public String getName()
{
return name;
}
Person(String n,int a)
{
name = n;
age = a;
System.out.println("c:name="+name+","+"age="+age);
cry();
}
public void cry()
{
System.out.println("cry....");
}
}
|
|