What does the following print?
public class Main { static interface Printable {} static class Rectangle implements Printable {} public static void main(String[] args) { Rectangle rect = new Rectangle(); boolean n = null instanceof Rectangle; boolean v = rect instanceof Printable; boolean b = rect instanceof Rectangle; System.out.println(n + " " + v + " " + b); } //w w w. j a va 2 s. com }
B.
While using null with instanceof compiles, it always returns false.
The other two instanceof calls show that instanceof can be used with both classes and interfaces.
They both return true, making Option B correct.