nerdexam
Oracle

1Z0-851 · Question #15

Given: 09. interface Foo { int bar(); } 10. 11. public class Sprite { 12. public int fubar( Foo foo ) { return foo.bar(); } 13. public void testFoo() { 14. fubar( 15. //insert code here 15 16. )…

The correct answer is C. new Foo() { public int bar() { return 1; }. See the full explanation below for the reasoning.

Question

Given: 09. interface Foo { int bar(); } 10. 11. public class Sprite { 12. public int fubar( Foo foo ) { return foo.bar(); } 13. public void testFoo() { 14. fubar( 15. //insert code here 15 16. ); 17. } 18. } Which code, inserted at line 15, allows the class Sprite to compile?

Options

  • AFoo { public int bar() { return 1; }
  • Bnew Foo { public int bar() { return 1; }
  • Cnew Foo() { public int bar() { return 1; }
  • Dnew class Foo { public int bar() { return 1; }

How the community answered

(30 responses)
  • A
    3% (1)
  • B
    3% (1)
  • C
    83% (25)
  • D
    10% (3)

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice