我不知道为什么我一直收到这个错误:
在我的方法中我有:
int option;
Object message[] = new Object[6];
message[0] = firstName;
message[1] = txtfirstName;
message[2] = lastName;
message[3] = txtlastName;
message[4] = gender;
message[5] = txtgender;
int response = JOptionPane.showConfirmDialog(null,message,"Register a Person",JOptionPane.OK_CANCEL_OPTION , JOptionPane.QUESTION_MESSAGE);
Parent parent = new Parent(txtfirstName.getText(),txtlastName.getText(),txtgender.getText());
creche.add(parent);`
在我的主要内容我设置了:
ArrayList<Parent> parent = new ArrayList<Parent>();
List<Person> school = new ArrayList<Person>();
MyApp app = new MyApp ();
`
我有父类和子类以及超类Person的子类。
错误:Parent parent = new Parent(var1,var2,var3,var4);
但这可行:Child child = new Child(var1,var2,var3,var4);
creche.add(child);
任何帮助?
答案 0 :(得分:3)
为了使其工作,需要将Parent类定义为具体类。
E.g。
public class Parent extends Person {
}
我猜它被定义为抽象类或接口。 (见下文)
E.g。
public interface Parent {
}
public abstract Class Parent {
}
您可能只需要将其声明为具体类,如上所述。
答案 1 :(得分:0)
无法实例化Abstract或Interfaces。只有子课程可以