题目条件:
1. It must be possible to create instances of Alpha and Beta from outside the packages in which they are defined.
2. When an object of type Alpha(or any potential subclass of Alpha)has been created,the instance variable alpha may never be changed.,
3. The value of the instance variable alpha must always be "A" for objects of type Alpha.
Modifiers
package alpha; private protected public
xxxxx class Alpha{
xxxxx String alpha;
xxxxx Alpha(){this("A")
xxxxx Alpha(String a){alpha=a;}
}
package beta;
xxxxx class Beta extends alpha.Alpha{
XXXXX Beta(String a){super(a);}
}
xxxxxx代表空格
answer:
public
private
public
protected
public
public
这几个答案分别都是怎么解释的呢?请高人来帮忙。
------解决方案--------------------------------------------------------
第一点,我说了: 估计这有个条件写掉了,应该是在定义Alpha以外的包里创建的Alpha对象的alpha值只能是"A"
public Beta(String a){super(a);} 创建的是一个Beta的对象吧...
虽然会生成一个看不见的Alpha对象..
当然如果认为Beta的对象向上转型是一个Alpha对象我也没话说..
那就不知道了