How does this java code work?
•
Java
public static void main(String[] args)
public static void main(String[] args) { int [][]shatner = new int[1][1]; int []rat = new int[4]; shatner[0] = rat; System.out.println(shatner[0][3]); }
Surprisingly, the output is 0. Why doesn't Java check for this indexoutofbound error?
Solution
Don't be surprised Shatner [0] is an array (rat) with a length of exactly 4 So shartner [0] [3] is rat [3], which happens to be 0
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码