wood burning stoves*
The moose likes Beginning Java and the fly likes why these code cannot be compiled??? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "why these code cannot be compiled???" Watch "why these code cannot be compiled???" New topic
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: 1746
    
    2
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: 18671
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: 1510
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
 
wood burning stoves
 
subject: why these code cannot be compiled???
 
Similar Threads
String[] args
Do I have the chance to use a String Constant as a Varible Name?
Confusion with generics
protected class
static class