class Person{ //姓名 String name; //性别 String gender; //年龄 private int age;
public void eat(){ System.out.println("纠结"); }
public void sleep(){ System.out.println("Zzzzzz........"); }
public void study(){ System.out.println("学习JavaSE"); }
public void show(){ System.out.println(name + "***"+gender+"***"+age); }
public void method(){ System.out.println(age); }
public void setAge(int a){ if(age >=1 && age <= 150){ age = a; } else{ System.out.println("错误的年龄"); } } public int getAge(){ return age; } } class PrivateTest{ public static void main(String[] args){ Person p = new Person(); p.name = "阿里巴巴"; p.gender = "男"; p.setAge(-35); p.show(); System.out.println(p.getAge()); } }
|