-1

I wrote below program but I am not able to understand the output.

public class Test {

    public static void main(String[] args) {
        int[] a = new int[5];
        System.out.println(a instanceof Object);
    }

}
E. Villiger
  • 876
  • 10
  • 27

3 Answers3

0

It will output True. Instanceof checks if the left one is from the class at the right of instanceof. Every class is subclass of Object class in Java so here it evaluates true.

Alan Ajax
  • 23
  • 10
0

Arrays, even if they're arrays of primitives, are objects, so the program outputs true.

Mureinik
  • 297,002
  • 52
  • 306
  • 350
0

Besides checking class assignance, instanceof also check for the SuperClasses of the left side.

In your case the Array extends Object is a instanceof Object

Marcos Vasconcelos
  • 18,136
  • 30
  • 106
  • 167