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:
* Line Comments
* Block Comments
* JavaDoc Comments.
*/
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);
}
}
}
Abhishek Reddy posted this at 02:51 — 13th July 2006.
He has: 3,348 posts
Joined: Jul 2001
The static field greeting is in an inner class CommentsExample. This isn't allowed in Java. To make it compile, either:
public static class CommentsExample {
'Indent your code, btw, or use [code] tags when posting on the forum so whitespace won't get lost.
Also, are you sure you need to comment that heavily? Even for an example...
brikz posted this at 07:41 — 15th July 2006.
They have: 2 posts
Joined: Jul 2006
Many tutorials are available at thesitewizard.com which may help with your script.
ac-webdesign.net
phiber posted this at 22:23 — 17th July 2006.
They have: 20 posts
Joined: Jul 2006
I'm not totally up to snuff on Java 5 but when I tried your information it did compile but I got a runtime exception.
Exception in thread "main" java.lang.NoSuchMethodError: main
I'm pretty sure I have my classpath set right. I might be doing something wrong here but figured this info might help.
Johnny
jetbrains posted this at 14:58 — 15th July 2006.
They have: 5 posts
Joined: Jul 2006
Static class is a new feature of java 5. i think you should post error message.
You can get many java tutorials from www.developerzone.biz and www.javaworld.com.
Funny Jokes || Hot Web Directory
EntireURL Directory
Want to join the discussion? Create an account or log in if you already have one. Joining is fast, free and painless! We’ll even whisk you back here when you’ve finished.