ProgrammingHardAmazon/Microsoft SDE MCQ · Java placement

What is printed?

What is printed?
Object o = null;
String s = (String) o;
System.out.print(s + (o instanceof Object) + (s == null));
  1. A. nulltruetrue
  2. B. It throws NullPointerException
  3. C. It throws ClassCastException
  4. D. nullfalsetrue

Correct answer: D. nullfalsetrue

Casting null to any reference type succeeds and gives null, so no exception. instanceof is always false for null, even against Object, and s == null is true.

More OOP with C++ and Java questions

Exams that ask this topic