I just did a test and I found a suspicious question, I would like your opinion.
In the Java programming language, when the method of a class
does not have an explicitly declared access modifier means that this method can be accessed(A) for all classes of the same package it was declared in.
(B) by any other class, other than that to which belongs.
(C) by the class to which it belongs, exclusively.
(D) by the class in which it was declared and its subclasses, and by members of other classes in the same package.
I think that answer D is correct, even in a test that I did the method behaved normally and with no problem at compile time and at runtime:
class Teste {
String teste() {
return "ola";
}
}
class Teste2 extends Teste {
}
class Principal {
public static void main(String[] args) {
Teste2 t = new Teste2();
System.out.println(t.teste());
}
}
The preliminary feedback reports that the correct answer is (A).