ProgrammingHardProduct-company placement · Java

What is printed?

What is printed?
Object o = new int[]{1};
System.out.print((o instanceof int[]) + " " + (o instanceof Object[]));
  1. A. true true
  2. B. true false
  3. C. false false
  4. D. Compile-time error: arrays cannot be tested with instanceof

Correct answer: B. true false

Every array is an Object, and int[] is its own reference type. But an int[] is not an Object[]: array covariance applies only to arrays of references.

More OOP with C++ and Java questions

Exams that ask this topic