Oracle
1Z0-809 · Question #2
1Z0-809 Question #2: Real Exam Question with Answer & Explanation
The correct answer is B. Java Jeve va. See the full explanation below for the reasoning.
Question
Given the class definitions:
class Alpha {
public String doStuff(String msg) {
return msg;
}
}
class Beta extends Alpha {
public String doStuff(String msg) {
return msg.replace('a', 'e');
}
}
class Gamma extends Beta {
public String doStuff(String msg) {
return msg.substring(2);
}
}
And the code fragment of the main() method,
12. List<Alpha> strs = new ArrayList<Alpha>();
13. strs.add(new Alpha());
14. strs.add(new Beta());
15. strs.add(new Gamma());
16. for (Alpha t : strs) {
17. System.out.println(t.doStuff("Java"));
18. }
What is the result?Options
- AJava Java Java
- BJava Jeve va
- CJava Jeve ve
- DCompilation fails
Community Discussion
No community discussion yet for this question.