我有一個叫做「問題」的超類。我有兩個從它派生的子類,稱爲「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