- class Student
- {
- private String name;
- private String id;
- private int age;
- static void sleep()
- {
- System.out.println("趴着睡觉");
- }
- static void eat()
- {
- System.out.println("学生餐");
- }
- static void action()
- {
- System.out.println("学习");
- }
- public void setName(String name)
- {
- name = name;
- runName(name);
- }
- public void steId(String id)
- {
- this.id = id;
- runId(id);
- }
- public void age(int age)
- {
- if (age>0 && age<120)
- {
- this.age = age;
- }
- else
- System.out.println("非法操作!");
- runAge(age);
- }
- public String getName()
- {
- return name;
- }
- public String getId()
- {
- return id;
- }
- public int getAge()
- {
- return age;
- }
- public void runNme(String name)
- {
- System.out.println(name);
- }
- public void runId(String id)
- {
- System.out.println(id);
- }
- public void runAge(int id)
- {
- System.out.println(age);
- }
- public static void printName(String name)
- {
- System.out.println("姓名:"+name);
- }
- public static void printid(String id)
- {
- System.out.println("id:"+id);
- }
- public static void printAge(int age)
- {
- System.out.println("年龄:"+age);
- }
- }
- class PersonTest8
- {
- public static void main(String[] args)
- {
- Student sd = new Student();
- sd.setName("ls");
- sd.setId("010");
- sd.setAge(40);
- }
- }
复制代码 |