第二个学生信息的输出
package hong;
public class Student {
String name;
String sex;
int age;
public Student(String name, String sex,int age){
this.name=name;
this.sex=sex;
this.age=age;
}
void ShowInfo(){
System.out.println("姓名:"+name);
System.out.println("性别:"+sex);
System.out.println("年龄:"+age);
}
public static void main(String[] args) {
// TODO 自动生成的方法存根
Student stu=new Student("王五","男",21);
System.out.println("学生信息");
stu.ShowInfo();
}
}
运行结果: