Christina Pong

+ Follow
since Sep 21, 2008
Merit badge: grant badges
For More
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Christina Pong

I think it is a pass-by-value trick, so easy to get caught here.
good quesiton. Thank you for post it :-)

I compiled both codes with eclipse; they were fine.
Hi Ankit,
Thanks for the reply. Wow, isn't it tricky?
The output is so much different than what you thought it supposed to be. Gosh, it beats me.
Byt the way, Ankit, you are so cool. You seem know all the answers or sources to those tricky questions. Great to have a pal like you in this forum :-)

code from John Meyer's SCJP5
int[] a= {1,2,3,4 };
for( int n :a){

a[n]= 0 ;

for ( int i : a )
System.out.println(i);//prints 0 0 3 0


can anybody tell me why above code doesn't thrown an IndexOutOfBound exception at runtime, instead having an output of 0 0 3 0?

Thanks !
the parameters you passed into method m1(int[] i1, int[] i2) are local variables, so whatever they are doing inside the method m1, is not going to affect the original i1, i2 which are defined in the main method. That's what happens in the code1.
However, in code2, the elements of two arrays really swap; i1[0] becomes 3, i2[0] becomes 1, that's why output is 3,1

I hope above is clear for your question. I had the similar problem before too :-)
Is there any way to check the number of objects being created during the execution? Thanks :-)
I am considering buying the SCJP 1.6 simulator from Whizlabs; have you guys ever bought this product? My concern is how safe is to pay payment by credit card online to this company? Anybody has any experience? Thanks :-)
a very good question. Thanks for posting :-)