谁给我说下这道Java提的的运行

来源:百度知道 编辑:UC知道 时间:2024/06/18 12:11:41
class Person{
private String guojia;
private String diqu;
private String shiqu;
private String name;
private int age;
private float shengao;
private float tizhong;
public Person(){};
public Person(String guojia,String diqu,String shiqu,String name,int age,float shengao,float tizhong){
this.SetGuojia(guojia);
this.SetDiqu(diqu);
this.SetShiqu(shiqu);
this.SetName(name);
this.SetAge(age);
this.SetShengao(shengao);
this.SetTizhong(tizhong);
}
public String GetInfo(){
return "\n"+"个人信息:" + "\t" +
"\n"+" -国家:" + GetGuojia() + "\t" +
"\n"+" -地区:" + GetDiqu() + "\t" +
"\n"+" -市区:" + GetShiqu()+ "\t" +
"\n"+" -名字:" +

public static void main(String args[]){
Person p1 = new Person("中国","陕西","西安","小鸟",17,174.0f,100.0f);
System.out.println(p1.GetInfo());
}
首先执行main函数.

Person p1 = new Person("中国","陕西","西安","小鸟",17,174.0f,100.0f);调用person类的有参数构造函数
public Person(String guojia,String diqu,String shiqu,String name,int age,float shengao,float tizhong){
this.SetGuojia(guojia);
this.SetDiqu(diqu);
this.SetShiqu(shiqu);
this.SetName(name);
this.SetAge(age);
this.SetShengao(shengao);
this.SetTizhong(tizhong);
}
生成对象p1.

System.out.println(p1.GetInfo());这句话可以划分为两步
首先是p1调用成员函数GetInfo();
public String GetInfo(){
return "\n"+"个人信息:" + "\t" +
"\n"+" -国家:" + GetGuojia() + "\t" +
"\n