62,614
社区成员
发帖
与我相关
我的任务
分享
public class ExtendsDemo02 {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
// 验证子类能否访问父类中的private属性或者方法
// 或者说继承?
child ch = new child();
ch.setage(10);
ch.name = "xiaomim";
System.out.println(ch);
System.out.println(ch.getage());
}
}
class person_private {
private int age;
String name;
public void setage(int age) {
this.age = age;
}
public int getage() {
System.out.println(this);
return this.age;
}
}
class child extends person_private {
void cry() {
System.out.println("wowo");
}
}
child@55f33675
child@55f33675
10