我有一个叫做“问题”的超类。我有两个从它派生的子类,称为“QuestionSA”(简答)和“QuestionTF”(真/假)。如何在java中访问另一个类的构造函数?
这是QuestionSA样子:
public class QuestionSA extends Question {
private static char[] givenAnswer;
// ========================================================
// Name: constructor
// Input: the type of question, the level,
// the question and answer, as strings
// Output: none
// Description: overloaded constructor that feeds data
// ========================================================
QuestionSA(String type, String level, String question, String answer) {
this.type = type;
this.level = level;
this.text = question;
this.answer = answer;
}
我需要从QuestionTF访问构造函数QuestionSA。我已经在C++中这样做了:
QuestionTF::QuestionTF(string type, string level, string question, string answer)
: QuestionSA(type, level, question, answer) {}
如何在Java中执行此操作?
你也可以添加QuestionTF类吗? – Jens
我必须编辑澄清。我知道这个命名表明这是儿童班,但我必须检查它的两倍。 – ByeBye
为什么'givenAnswer'是静态的? – tkausl