I've looked for an answer to this question and haven't found anything. Hopefully I haven't missed a post somewhere.
Background: I'm studying for the
SCJP at a technical school where, unfortunately, none of the instructors at my location are
Java experts. I'm stumped by the answer to one of the questions about the following code snippet (commented lines are those I've added to get the code to compile, line numbers as in the
test question):
1. class SuperClass {
// public class A {
2. public A getA() {
3. return new A();
4. }
// }
5. }
6. class SubClass extends SuperClass {
// public class B {
7. public B getA() {
8. return new B();
9. }
// }
10. }
The "correct" answer says: "Compilation will succeed if B extends A." Other, "incorrect" answers are that A. compilation will fail because of an error in line 3 and that B. compilation will fail because of an error in line 9.
Given that I had to add code to even get the original code to compile (and doing so without "B extending A"), any thoughts on how the code should look to get to the answer as stated? What concept are they trying to test here? NetBeans pukes on lines 2, 3, 7, & 8.
Thanks!