nerdexam
Oracle

1Z0-851 · Question #38

Given: public class Base { public static final String FOO = "foo"; public static void main(String[] args) { Base b = new Base(); Sub s = new Sub(); System.out.print(Base.FOO)…

The correct answer is D. foobarfoobarfoo. See the full explanation below for the reasoning.

Question

Given: public class Base { public static final String FOO = "foo"; public static void main(String[] args) { Base b = new Base(); Sub s = new Sub(); System.out.print(Base.FOO); System.out.print(Sub.FOO); System.out.print(b.FOO); System.out.print(s.FOO); System.out.print(((Base)s).FOO); } } class Sub extends Base {public static final String FOO="bar";} What is the result?

Options

  • Afoofoofoofoofoo
  • Bfoobarfoobarbar
  • Cfoobarfoofoofoo
  • Dfoobarfoobarfoo
  • Ebarbarbarbarbar
  • Ffoofoofoobarbar
  • Gfoofoofoobarfoo

How the community answered

(33 responses)
  • A
    3% (1)
  • C
    9% (3)
  • D
    85% (28)
  • G
    3% (1)

Community Discussion

No community discussion yet for this question.

Full 1Z0-851 Practice