The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
June 2000



This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.


Solution to your doubt on array declaration

Posted by S Subbu Arunachalam on October 19, 2000 at 12:26 AM

> Dear Programmers
> I faced a small problem in compiling a small java program during my scjp preparation. I have declared an single dimentional array at class level and tried to allocate memory in the next statement using new operator. but it is giving compile time error, identifier expected. i could do same thing in a method without any errors. i could also declare it at class level and
> allocate memory in the constructor with out any problem
> code fragement:
> class ArrayDecl{
> int ints[];
Hi nanacharaiah,
I read your problem accidently when i was searching for scjp preparation
The problem is quite simple. Because at class level you can only declare
variables or assign a value while declaring. But you can't assign
a value in a seperate statement. You can assign a value to variable
inside a method or inside an constructor but you can't in class level.
That's all.


Sponsored Links

Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us