//输入一个人的信息,然后输出,其中有错误,见注释,为什么?
public class Person {
private String name;
private int age;
private String address;
public String getName(){
return name ;
}
public int getAge(){
return age;
}
public String getAddress(){
return address;
}
public void changeName (String new_name){
name=new_name;
}
// public void incAge(){
// age++;
// }
public void setAge(int new_age){
age=new_age;
}
public void setAddress(String x){
address=x;
}
// public String toString(){
// String s="Name:"+name+"\n";
// s+="Age"+age+"\n";
// s+="Address:"+address+"\n";
// return s;
// }
public static void main(String[] args){
Person p1=new Person();
Person p2=new Person();
p1.changeName("Jone");
p1.setAge(23);
p1.setAddress("江西");//错误???
// p1.incrementAge();
p2.changeName("Mary Ann");
p2.setAge(60);
p2.setAddress("北京");//错误???
System.out.println("姓名="+p1.getName()+",年龄="+p1.getAge()+",地址="+p1.getAddress());
System.out.println("姓名="+p2.getName()+",年龄="+p2.getAge()+",地址="+p2.getAddress());
}
}
[此贴子已经被作者于2007-9-30 11:43:21编辑过]