| Author |
why these code cannot be compiled???
|
smart andy
Greenhorn
Joined: Apr 08, 2002
Posts: 2
|
|
why cannot i creat a String Array??? pubic class andy { String[] a = new String[3]; a[0]="aaaa" a[1]="bbbb" a[2]="cccc" public static void main(String[] args){} } wait for you answer. ....
|
(:... <img src="smile.gif" border="0">
|
 |
Michael Matola
whippersnapper
Ranch Hand
Joined: Mar 25, 2001
Posts: 1721
|
|
|
Well, for starters, those assignments aren't inside any method or (initialization) block, so I bet the compiler gave you a whole slew of error messages.
|
 |
Dirk Schreckmann
Sheriff
Joined: Dec 10, 2001
Posts: 7023
|
|
|
...and there's that whole missing semicolons thing...
|
[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
|
 |
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
|
|
Let's not forget the "pubic class"
|
"I'm not back." - Bill Harding, Twister
|
 |
andy lau
Ranch Hand
Joined: Apr 08, 2002
Posts: 51
|
|
|
why???
|
 |
Bosun Bello
Ranch Hand
Joined: Nov 06, 2000
Posts: 1506
|
|
|
Andy, what do you mean? You don;t understand what Michael, Dirk, and Jim posted?
|
Bosun (SCJP, SCWCD)
So much trouble in the world -- Bob Marley
|
 |
andy lau
Ranch Hand
Joined: Apr 08, 2002
Posts: 51
|
|
|
i don't understand why assignments can't be initialized outof method or (initialization) block
|
 |
Cindy Glass
"The Hood"
Sheriff
Joined: Sep 29, 2000
Posts: 8521
|
|
smart andy, Welcome to the Java Ranch, we hope you’ll enjoy visiting as a regular however, your name is not in keeping with our naming policy here at the ranch. Please change your display name to an appropriate name as shown in the policy. (Hint: please do not use any obviously fictitious names). Thanks again and we hope to see you around the ranch!!
|
"JavaRanch, where the deer and the Certified play" - David O'Meara
|
 |
andy lau
Ranch Hand
Joined: Apr 08, 2002
Posts: 51
|
|
but these code can also be compiled(without static),look: public class andy{ {String[] a = new String[3]; a[0]="sfdgc"; a[1]="a"; a[2]="b"; } public static void main(String[] args){} } [ April 10, 2002: Message edited by: andy lau ]
|
 |
Charlie Sturman
Ranch Hand
Joined: Apr 04, 2002
Posts: 112
|
|
Originally posted by andy lau: i don't understand why assignments can't be initialized outof method or (initialization) block
The compiler puts all static and instance initializers of a class into one special method,the class initialization method.Only the jvm at runtime invokes this special initialization method. I feel like I am aiming at a moving target
|
 |
 |
|
|
subject: why these code cannot be compiled???
|
|
|