Bookmark Topic Watch Topic
  • New Topic

Please explain me this!  RSS feed

 
Sonam Arya
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Report post to moderator
Can someone explain me why the output of the two classes are what it results:

public class example 1{
int i[] = {0};
public static void main(String args[]) {
int i[] = {1};
change_i(i);
System.out.println(i[0]);
}
public static void change_i(int i[]) {
i[0] = 2;
i[0] *= 2;
}
}



public class example2 {
int i[] = {0};
public static void main(String args[]) {
int i[] = {1};
change_i(i);
System.out.println(i[0]);
}
public static void change_i(int i[]) {
int j[] = {2};
i = j;
}
}
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66304
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Report post to moderator
"ScreenSunCert Desire", please check your private messages for an important administrative matter.

Also, please do not cross-post the same question in multiple forums. It wastes people's time when multiple redundant conversations take place. Please read this for more information.
 
    Bookmark Topic Watch Topic
  • New Topic
Boost this thread!