"Question"라는 수퍼 클래스가 있습니다. 나는 "QuestionSA"(짧은 대답)와 "QuestionTF"(참/거짓)이라는 두 개의 하위 클래스를 파생시킵니다.java에서 다른 클래스의 생성자에 액세스하는 방법은 무엇입니까?
이 같은 QuestionSA는 모습입니다 : 내가 QuestionTF에서 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;
}
. 나는 C++에서 이렇게했습니다 :
QuestionTF::QuestionTF(string type, string level, string question, string answer)
: QuestionSA(type, level, question, answer) {}
Java로 어떻게 할 수 있습니까?
QuestionTF? 클래스를 추가 할 수 있습니까? – Jens
명확히하기 위해 편집해야합니다. 이 명명은 자식 클래스라는 것을 알았지 만 이중 검사를해야했습니다. – ByeBye
왜'givenAnswer'는 정적입니까? – tkausl