Oracle
1Z0-851 · Question #12
Given: class Alpha { public void foo() { System.out.print("Afoo "); } } public class Beta extends Alpha { public void foo() { System.out.print("Bfoo "); } public static void main(String[] args) {…
The correct answer is D. Bfoo Bfoo. See the full explanation below for the reasoning.
Question
Given: class Alpha { public void foo() { System.out.print("Afoo "); } } public class Beta extends Alpha { public void foo() { System.out.print("Bfoo "); } public static void main(String[] args) { Alpha a = new Beta(); Beta b = (Beta)a; a.foo(); b.foo(); } } What is the result?
Options
- AAfoo Afoo
- BAfoo Bfoo
- CBfoo Afoo
- DBfoo Bfoo
- ECompilation fails.
- HAn exception is thrown at runtime.
How the community answered
(21 responses)- A5% (1)
- C10% (2)
- D81% (17)
- H5% (1)
Community Discussion
No community discussion yet for this question.