Oracle
1Z0-851 · Question #35
Given: class Foo { public int a = 3; public void addFive() { a += 5; System.out.print("f "); } } class Bar extends Foo { public int a = 8; public void addFive() { this.a += 5; System.out.print("b "…
The correct answer is A. b 3. See the full explanation below for the reasoning.
Question
Given: class Foo { public int a = 3; public void addFive() { a += 5; System.out.print("f "); } } class Bar extends Foo { public int a = 8; public void addFive() { this.a += 5; System.out.print("b " ); } } Invoked with: Foo f = new Bar(); f.addFive(); System.out.println(f.a); What is the result?
Options
- Ab 3
- Bb 8
- Cb 13
- Df 3
- Ef 8
- Ff 13
- GCompilation fails.
- HAn exception is thrown at runtime.
How the community answered
(32 responses)- A75% (24)
- C6% (2)
- F3% (1)
- G3% (1)
- H13% (4)
Community Discussion
No community discussion yet for this question.