我正在制作一个小程序时遇到问题。基本上我有6个班。1个主类,4个“扩展”主类的子类和另一个运行程序的类。到目前为止,运行程序的类是这样安排的:
public class ClassToRunProgram {
public void main(String[] args){
Class1 a = new Class1(0, "class1"); //I've created 1 main class (Class5) that
Class2 b = new Class2(1, "class2"); //these 4 classes extend.
Class3 c = new Class3(2, "class3");
Class4 d = new Class4(3, "class4");
int randomNum = (int) (Math.random() *3);
Class5[] arrayForClasses = new Class5[]{a, b, c, d}; //since they're extending this
//class I want to make them into
//a single Array?
String numberQuestion = JOptionPane.showInputDialog(null,
"What question do you want to ask? \n
Enter a number: \n
1. First Question? \n
2. Second Question? \n
3. Third Question?");
int question = Integer.parseInt(numberQuestion); //not sure if this part is
//actually relevant at all??
//Think it might be since I want to
//use integers in my if statement below
if(question == 1){
JOptionPane.showMessageDialog(null, "Blah blah"+arrayForClasses.getReturnValue()+" blah");
}
.getReturnValue() 方法在所有类 (1-5) 中。我不确定这是否真的是我必须做的。但是我遇到的问题是,当我编译它时(即使它没有完成),它会抛出一个“无法找到符号”错误消息“符号:方法 .getReturnValue()位置:变量 arrayForClasses 类型 Class5 []” . 我只是想知道我哪里错了?
任何帮助深表感谢。
谢谢!