我不知道为什么我总是收到这个错误:
在我的方法中我有:
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 ();
`
我有父类和子类以及父类(super class) Person。
错误:Parent parent = new Parent(var1,var2,var3,var4);
但这有效:Child child = new Child(var1,var2,var3,var4);<br/>
creche.add(child);
有什么帮助吗?
最佳答案
为此,需要将父类定义为具体类。
例如
public class Parent extends Person {
}
我猜它被定义为抽象类或接口(interface)。 (见下文)
例如
public interface Parent {
}
public abstract Class Parent {
}
您可能只需要像上面那样将其声明为具体类。
关于java - 无法实例化父类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15198812/