For example,
public class Question {
protected String question, correctAnswer, type;
....
}
public class MultipleChoice extends Question{{
...
}
public class TrueFalse extends MultipleChoice{
public TrueFalse(){
this.type = "TrueFalse";
this.question = "Question is not assinged!";
this.correctAnswer = "Correct Answer is not assinged!";
}
....
}
It is clear that class MultipleChoice
can access the question, type, and correctAnswer
in class Question
. But when I try to access them in class TrueFalse
bythis.a
. I got an error.
cannot be resolved or is not a field
.
Thus, is the protected attribute in a class is only accessible in its subclass, but not sub-subclass? Three files are in the same package but different class file.