public class Student {
String name;
String sex;
int age;
public Student(){};
public Student(String a,String b,int c)
{
name=a;
sex=b;
age=c;
}
void getInfo(String a,String b,int c)
{
name=a;
sex=b;
age=c;
}
void showInfo(){
System.out.println("姓名:"+name);
System.out.println("性别:"+sex);
System.out.println("年龄:"+age);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
Student stu1;
stu1=new Student();
System.out.println("输出第一个人的信息");
stu1.getInfo("张宏","男",23);
stu1.showInfo();
System.out.println("输出第二个人的信息");
Student Stu2=new Student("周杰","男",18);
Stu2.showInfo();
System.out.println("输出第三个人的信息");
Student Stu3=new Student("杜清","女",20);
Stu3.showInfo();
System.out.println("输出第四个人的信息");
Student Stu4=new Student("王美","女",22);
Stu4.showInfo();
}
}
类和对象
最新推荐文章于 2023-05-03 22:23:19 发布