| Home | Register | FAQ | Members List | Search | Today's Posts | Mark Forums Read |
|
|
#1 (permalink) |
|
Registered User
Join Date: Jun 2006
Posts: 3
|
Java codin help
keep gettin 2 error messages (1)The field greeting cannot be declared static; static fields can only be declared in static or top level types this is what the code looks like public class comment { /** * @author Craig * * This class demonstrates use of:<br> * Line Comments<br> * Block Comments<br> * JavaDoc Comments.<br> */ public class CommentsExample { /** * Program comments are nonexecuting, * statements you add to a program * documentation for the purpose * of documentation. */ protected static String greeting = "Hi"; //Program comments are nonexecuting, //statements you add to a program private static String name = "Guys"; //documentation for the purpose public CommentsExample() { //of documentation.() super(); } /** * This is the entry point of the application. * main() is executed first by the JVM. */ public void main(String[] args) { /* * Program comments are nonexecuting, * statements you add to a program * documentation for the purpose * of documentation. */ System.out.println(greeting + " " + name); } } } |
|
|
|
|
|
#2 (permalink) |
|
mingin dawg baitch
|
You'd be better off in a Java forum...we dont use java round these parts generally. But I'd guess that its cause your class is nested (public class CommentsExample ). Static fields need to be in the top level class, and are inherited. Try moving it to class comment. |
|
|
|
#3 (permalink) |
|
Registered Abuser
Join Date: Jun 2006
Location: Manchester, England.
Posts: 174
|
That's a really bizarre example. Why the outer class "comment"? Get rid of it and all will be ok (or do as paulanthony suggests, but then I don't know why you'd want an inner class anyway). |
|
![]() |