class Test13{ public static void main(String[] args){ Student s1 = new Student("小王",24,99);//有参构造创建对象 Student s2 = new Student();//无参构造创建对象 s2.setName("小李"); //set方法修改s2属性 s2.setAge(24); //set方法修改s2属性 s2.setScore(78); //set方法修改s2属性 System.out.println(s1.getInfo());//用getInfo()方法返回学生1信息 System.out.println(s2.getInfo());//用getInfo()方法返回学生2信息 } } class Student{ private String name; private int age; private int score; //有参构造器 public Student(String n,int a,int s){ name = n; age = a; score = s; } //无参构造器 public Student(){ } //公共的getset方法 public void setName(String n){ name = n; } public String getName(){ return name; } public void setAge(int a){ age = a; } public int getAge(){ return age; } public void setScore(int s){ score = s; } public int getScore(){ return score; } //提供getInfo方法 public String getInfo(){ return "姓名: "+name+" 年龄: "+age+" 成绩: "+score; } }