aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what is the output here.. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "what is the output here.." Watch "what is the output here.." New topic
Author

what is the output here..

Preethi Dev
Ranch Hand

Joined: Sep 07, 2008
Posts: 265
Hi,
I got it from Deepak Bala's website.
Can anyone tell me what is the output?

class arraymock
{
public static void main(String args[])
{
int[] arr={1,2,3,4,5};
int[] aar2=new int[4];
arr2=arr; //cannot find symbol in arr2=arr
System.out.println(arr2[4]); //cannot find symbol in arr2[4]
}
}

when i tried this i got these 2 errors,but the answer given is it prints 5.

if this is true ,please clear me ...


Thanks in advance

Preparing scjp 1.5
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

This code should run perfectly and give output as 5


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Preethi Dev
Ranch Hand

Joined: Sep 07, 2008
Posts: 265
agaign i tried the same code ,now its giving 5. I am just checking the code but couldnt find where i did wrong.
Ravissant Markandey
Ranch Hand

Joined: Oct 24, 2007
Posts: 41
Hi Preetha,
Go through your code again, the array variable names are different(arr /aar).

regards,
Ravissant Markenday
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9293
    
  17

Ravissant you got me! That was brilliant. I read the code three times and could not recognize that error....
Ravissant Markandey
Ranch Hand

Joined: Oct 24, 2007
Posts: 41
My apologies, i meant arr2 and aar2.
Preethi Dev
Ranch Hand

Joined: Sep 07, 2008
Posts: 265
thanks now i got.
 
jQuery in Action, 2nd edition
 
subject: what is the output here..