Oracle's sample Java SE 7 Programmer I questions
Posted: Tue Dec 18, 2012 8:10 pm
Oracle has a few sample questions for the certificate exam on http://education.oracle.com/pls/web_pro ... =SQ1Z0_803. One sample question has me baffled and I was hoping you could help. The question is this:
The correct answer is C. I expected D. I assume this is a test of shadowing, but I can't see how super.type could be shadowed.
Can you explain this?
Thanks.
Code: Select all
7. Given:
class Feline {
public String type = "f ";
public Feline() { System.out.print("feline "); }
}
public class Cougar extends Feline {
public Cougar() { System.out.print("cougar "); }
public static void main(String[] args) {
new Cougar().go();
}
void go() {
type = "c ";
System.out.print(this.type + super.type);
}
}
What is the result?
A) cougar c c
B) cougar c f
C) feline cougar c c
D) feline cougar c f
E) Compilation fails
F) An exception is thrown at run time.
Can you explain this?
Thanks.