Oracle
1Z0-809 · Question #2
Given the class definitions: ``java class Alpha { public String doStuff(String msg) { return msg; } } class Beta extends Alpha { public String doStuff(String msg) { return msg.replace('a', 'e'); } }…
The correct answer is B. Java Jeve va. You've hit your session limit · resets 5:20pm (America/New_York)
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
How the community answered
(26 responses)- A4% (1)
- B85% (22)
- C8% (2)
- D4% (1)
Explanation
You've hit your session limit · resets 5:20pm (America/New_York)
Community Discussion
No community discussion yet for this question.