Oracle
1Z0-851 · Question #140
Given: interface Fish { } class Perch implements Fish { } class Walleye extends Perch { } class Bluegill { } public class Fisherman { public static void main(String[] args) { Fish f = new Walleye()…
The correct answer is B. f-p w-f. See the full explanation below for the reasoning.
Question
Given: interface Fish { } class Perch implements Fish { } class Walleye extends Perch { } class Bluegill { } public class Fisherman { public static void main(String[] args) { Fish f = new Walleye(); Walleye w = new Walleye(); Bluegill b = new Bluegill(); if(f instanceof Perch) System.out.print("f-p "); if(w instanceof Fish) System.out.print("w-f "); if(b instanceof Fish) System.out.print("b-f "); } } What is the result?
Options
- Aw-f
- Bf-p w-f
- Cw-f b-f
- Df-p w-f b-f
- ECompilation fails.
- FAn exception is thrown at runtime.
How the community answered
(21 responses)- B71% (15)
- D10% (2)
- E14% (3)
- F5% (1)
Community Discussion
No community discussion yet for this question.