如果我创建一个扩展类对象的arrayList,那没关系。
EX:
Class A {
private aa;
}
Class B extends A {
private ArryList <A>;
}
我希望我的B类应该具有A的所有值和A的数组列表。
除了使用相同的参数创建两个不同的类之外,还有其他方法吗?
或者这种方法对我有用吗?
答案 0 :(得分:0)
我认为你需要使用这样的getter和setter:
Class A {
private int aa;
public int getAA(){
return aa;
}
public void setAA(int aa){
this.aa = aa;
}
}
Class B extends A {
private ArryList <A> aaa;
}
你也可以这样说@Pradeep Simha并制作protected int aa
现在你可以访问B类的一个字段
答案 1 :(得分:0)
你的设计应该有效。
class Reply
{
}
class Comment extends Reply
{
private List<Reply> repliesToComment;
}