入迷英语

您现在的位置是:首页 > 企业英语 > 正文

企业英语

设计一个程序,包含两个类。一个是People类(人),有“姓名”和“年龄”两个属性,一个自我介绍的方法?

zxc2021-09-17企业英语66

public class People {

private String Name;

private int age;

public void Introduce(){

System.out.println(大家好!我叫+Name + ,今年+age+岁);

}

public People(String name, int age) {

Name = name;

this.age = age;

}

public String getName() {

return Name;

}

public void setName(String name) {

Name = name;

}

public int getAge() {

return age;

}

public void setAge(int age) {

this.age = age;

}

}

public class PeopleInstance {

public static void main(String[] args) {

People pe1 = new People(小强,21);

People pe2 = new People(宝宝,22);

pe1.Introduce();

pe2.Introduce();

}

}