Old 12-07-2006, 12:54   #1 (permalink)
benzspida
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);
}
}
}
  Reply With Quote
Old 13-07-2006, 12:28   #2 (permalink)
paulanthony
mingin dawg baitch
 
paulanthony's Avatar
 
Join Date: Apr 2004
Location: Belfast
Posts: 1,035
Send a message via MSN to paulanthony
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.
  Reply With Quote
Old 13-07-2006, 14:30   #3 (permalink)
sjd
Registered Abuser
 
sjd's Avatar
 
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).
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8