首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2SE开发 >

抱歉,小弟我也不想炒老帖。java private属性继承有关问题

2012-01-10 
抱歉,我也不想炒老帖。java private属性继承问题Java codepublic class Test extends A{public static void

抱歉,我也不想炒老帖。java private属性继承问题

Java code
public class Test extends A{    public static void main(String[] args)    {        System.out.println(new Test().a);        System.out.println(new Test().b);    }}class A{    private int a;}

报错如下:
The field A.a is not visible
b cannot be resolved or is not a field
这是不是可以说明,private 的a被继承了呢?

[解决办法]
引用Java Language Specification 3的原话:
A private class member or constructor is accessible only within the body of the
top level class (§7.6) that encloses the declaration of the member or constructor. It
is not inherited by subclasses.

热点排行