//一个人员信息,怎样将他们输出?
public class Personn {
private String name;
private int age;
private String address;
public Personn(String myname,int myage,String myaddress){//构造方法
name=myname;
age=myage;
address=myaddress;
}
public static void main(String[] args){
Personn p3=new Personn("Will",21,"Hubei");
//输出.........................................
}
}
[此贴子已经被作者于2007-9-30 11:40:09编辑过]
----------------解决方案--------------------------------------------------------
装成Bean.调相应的方法
----------------解决方案--------------------------------------------------------
//一个人员信息,怎样将他们输出?
public class Personn {
private String name;
private int age;
private String address;
public Personn(String myname,int myage,String myaddress){//构造方法
name=myname;
age=myage;
address=myaddress;
}
public static void main(String[] args){
Personn p3=new Personn("Will",21,"Hubei");
//输出.........................................
System.out.println(p3.name+p3.age+p3.address);
}
}
----------------解决方案--------------------------------------------------------
重写toString()方法
造Person类中添加
public String toString(){
return("Name:"+name+" Age:"+age+" Address:"+address);
}
输出时直接
System.out.println(p3);
就行了
格式为:Name:Will Age:21 Address:Hubei
----------------解决方案--------------------------------------------------------