private私有
package com.oracle.Demo01; public class Person { private String name; private int age; public void setName(String name) { this.name = name; } public String getName() { return name; } public void setAge(int age) { if (age >= 0 && age <= 130) { this.age = age; } else { System.out.println("你输入的年龄不正确"); } } public int getAge() { return age; } public void speak() { System.out.println(name + "..." + age); } public boolean compare(Person p) { return this.age == p.age; } }