本帖最后由 顾传文 于 2013-3-12 09:11 编辑
package com.itheima;
public class Test01 {
public static void main(String[] args) {
Zi zi = new Zi(3);
System.out.println(zi.getNum());
}
}
class Fu{
private int num;
int age;
public Fu(int num){
this.num = num;
age = 60;
}
public int getNum(){
return num;
}
}
class Zi extends Fu{
private int num = 6;
public Zi(int num){
super(num);
}
}
打印的结果为3。记得子类不能继承父类的private类型的属性和方法,为什么打印的结果不是6呢? |