Practice mode Java

What is the output of the Java code int m = new int; System.out.println(m == null);?

Correct answer C. true

Explanation

Java builds two-dimensional arrays as arrays of arrays. The expression new int[2][] creates only the outer array, whose elements are references of type int[] with the default value null, so the comparison is true. Comparing null is safe, whereas reading m[0][0] before assigning an inner array would throw a NullPointerException.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.