- class pDemo
- {
- public static void main(String[] args)
- {
- per x = new per(10,"白");
- boolean tf=x.cmpAge(new per(20,"黑"));
- System.out.println(tf);
- }
- }
- //---------------下面是person类
- class per
- {
- private int age;
- private String name;
- public per(int age,String name)
- {
- setP(age,name);
- }
- public void setP(int age,String name)
- {
- this.age=age;
- this.name=name;
- }
-
- public void getP()
- {
- System.out.println("age="+age+" name="+name);
- }
- public boolean cmpAge(per p)
- {
- return this.age>p.age; //我的问题就是这里p.age为什么可以获取到值,
- } //它不是另外一个对象里面private 定义的私有成员吗
- //难道是因为它是同一个类实例出来的对象?
- }
复制代码 返回结果是false。
|