Can u explain the following codes for me more detailly?

ely (Ely)
public class example {
int i[] = {0};
public static void main(String args[]) {
int i[] = {1};
//When the code is executed,first this change_i's i[] points to the i[] which is declared and instanciated in main(), then the main call the routine change_i,after executing "i=j" in it ,the i(a local variable of change_i routine) point to j,in the meantime ,there are two array instance in the memory,so it has no relation with "i" that is declared in main()
//anser is c,the output is 1
public static void change_i(int i[]) {
int j[] = {2}; //"j[]"'s visibility is local
i = j; //"i" points to "j"

A. The program does not compile.
B. The program prints 0.
C. The program prints 1. (right)
D. The program prints 2.
E. The program prints 4.
2000-11-27 -04:00
This post has been archived. It cannot be replied.
Page address has been copied. To share, click to copy page address.
Share Online by QR Code

Back To Topic: What's the difference between "int a[] = new int[5]" and "int[] a = new int[5]"?

Back To Forum: HOME枫下论坛枫下论坛主坛工作学习IT技术讨论