我是 Java 新手,所以我可能在这里遗漏了一些东西——我在其他线程中环顾四周,但没有发现任何与我的问题非常相似的东西。我知道子类不会继承私有变量。我遇到的问题,为什么 super(); 在我的子构造函数中识别我的基本构造函数中的字段?父类中的构造函数是公共的吗?即使它传递的变量是私有的,子构造函数也会识别它们并传递它们吗?任何澄清将不胜感激。
父类:
public abstract class BaseQuestion {
private String questions;
private float totalAttempts;
private float averageTime;
private float percentCorrect;
public BaseQuestion(String questions, float totalAttempts, float averageTime, float percentCorrect){
this.questions = questions;
this.totalAttempts = totalAttempts;
this.averageTime = averageTime;
this.percentCorrect = percentCorrect;
}
子班:
public class TrueFalseQuestion extends BaseQuestion{
public static int questionsCreated;
public TrueFalseQuestion(String question, float totalAttempts, float averageTime, float percentCorrect){
super(question, totalAttempts, averageTime, percentCorrect);
}
编译器没有给我上面的错误,这让我有点困惑......
谢谢,