aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Can anyone explain please 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 "Can anyone explain please " Watch "Can anyone explain please " New topic
Author

Can anyone explain please

Soum Sark
Ranch Hand

Joined: May 31, 2002
Posts: 50
Hi:
Just on the question below. Why is line 5 not compiling. It must be something very simple I am missing here...any help would be appreciated
1. class ArrayTest {
2.
3. static int [ ] intArray = new int [5] ;
4. static int [ ] intArray1 = new int [1] ;
5. intArray1 [0] = 5 ;
6. static char [ ] charArray = new char [5] ;
7.
8. public static void main (String [ ] args) {
9.System.out.println (charArray [1] ) ;
10.intArray1 = intArray ;
11.intArray = charArray ;
12. }
13. }

a. The compiler objects to line 5.
b. The compiler objects to line 10.
c. The compiler objects to line 11.
d. Omitting lines 5,10 and 11 would make the program print 0.
e. There is nothing wrong with the code and the program prints 0
Dan Chisholm
Ranch Hand

Joined: Jul 02, 2002
Posts: 1865
Line 5 is an assignment statement so it must appear in a code block such as a method or constructor body or an initializer block.


Dan Chisholm<br />SCJP 1.4<br /> <br /><a href="http://www.danchisholm.net/" target="_blank" rel="nofollow">Try my mock exam.</a>
Sachin Choudhari
Greenhorn

Joined: Jul 02, 2002
Posts: 10
Hi Soum,
You can declare and initialize an array at the same time. But you can not initialize it seperately out side the method.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can anyone explain please