package ren.redface.demo; /* * 学生类 */ public class Student { private String name; private int age; 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 static void main(String[] args) { //创建对象 Student s = new Student(); System.out.println(s.getName()+"---"+s.getAge()); s.setName("林青霞"); s.setAge(28); System.out.println(s.getName()+"---"+s.getAge()); } }
或者建两个class
package ren.redface.demo; /* * 学生类 */ public class Student { private String name; private int age; public void setName(String n) { name = n; } public String getName() { return name; } public void setAge(int a) { age = a; } public int getAge() { return age; } }
package ren.redface.demo; /* * 学生类的测试类 */ public class StudentDemo { public static void main(String[] args) { //创建对象 Student s = new Student(); System.out.println(s.getName()+"---"+s.getAge()); s.setName("林青霞"); s.setAge(28); System.out.println(s.getName()+"---"+s.getAge()); } }