nerdexam
Oracle

1Z0-851 · Question #31

Given: 01. interface A { public void aMethod(); } 02. interface B { public void bMethod(); } 03. interface C extends A,B { public void cMethod(); } 04. class D implements B { 05. public void…

The correct answer is F. If you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod() defined in Line 9. See the full explanation below for the reasoning.

Question

Given: 01. interface A { public void aMethod(); } 02. interface B { public void bMethod(); } 03. interface C extends A,B { public void cMethod(); } 04. class D implements B { 05. public void bMethod(){} 06. } 07. class E extends D implements C { 08. public void aMethod(){} 09. public void bMethod(){} 10. public void cMethod(){} 11. } What is the result?

Options

  • ACompilation fails because of an error in line 3.
  • BCompilation fails because of an error in line 7.
  • CCompilation fails because of an error in line 9.
  • DIf you define D e = new E(), then e.bMethod() invokes the version of bMethod() defined in Line 5.
  • EIf you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod() defined in Line 5.
  • FIf you define D e = (D)(new E()), then e.bMethod() invokes the version of bMethod() defined in Line 9.

How the community answered

(20 responses)
  • A
    10% (2)
  • B
    15% (3)
  • E
    5% (1)
  • F
    70% (14)

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice