nerdexam
Oracle

1Z0-851 · Question #71

Given: interface A { void x(); } class B implements A { public void x() {} public void y() {} } class C extends B { public void x() {} } and: 20. java.util.List<A> list = new…

The correct answer is F. Compilation fails because of an error in line 25. See the full explanation below for the reasoning.

Question

Given: interface A { void x(); } class B implements A { public void x() {} public void y() {} } class C extends B { public void x() {} } and: 20. java.util.List<A> list = new java.util.ArrayList<A>(); 21. list.add(new B()); 22. list.add(new C()); 23. for (A a : list) { 24. a.x(); 25. a.y(); 26. } What is the result?

Options

  • AThe code runs with no output.
  • BAn exception is thrown at runtime.
  • CCompilation fails because of an error in line 20.
  • DCompilation fails because of an error in line 21.
  • ECompilation fails because of an error in line 23.
  • FCompilation fails because of an error in line 25.

How the community answered

(26 responses)
  • A
    12% (3)
  • B
    4% (1)
  • C
    4% (1)
  • D
    4% (1)
  • F
    77% (20)

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice