Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 08-18-2006, 12:48 AM   #1 (permalink)
benzspida
Registered User
 
Join Date: Jun 2006
Posts: 10
benzspida is on a distinguished road
Java Error can any one help

I keep getting this java error (inner class cannot have static declarations ) dont know why I just started learning Java dont know what im doing wrong. Thanks



Code:
import java.applet.Applet;
import java.awt.Graphics;
import java.awt.event.*;

public class comments extends Applet
  {
	/**
	 * @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  
		
		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);
		}
	}
}
benzspida is offline   Reply With Quote
Old 08-18-2006, 01:58 AM   #2 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,161
Belisarius is on a distinguished road
You've declared a class withing a class. Being that you're just starting Java, this is probably not what you want to do - it's a more advanced technique, and generally not neccessary.

Furthermore, you call "super()" in the constructor ("public CommentsExample()") of your inner class. This calls the constructor of the parent class. You are not extending CommentsExample from anything, so the "super()" call is superfluous.

You are not doing anything applet-ly, so you can remove the "public class comments extends Applet" declaration. Then your program should work. Just realize it won't be an applet - you'll need to run it from the command line.
__________________
GitS
Belisarius is offline   Reply With Quote
Old 04-17-2008, 04:52 PM   #3 (permalink)
Kevin1991
Recruit
 
Join Date: Apr 2008
Posts: 1
Kevin1991 is on a distinguished road
isnt that called recursion... or something along the lines of that?
Kevin1991 is offline   Reply With Quote
Old 04-18-2008, 06:50 AM   #4 (permalink)
redhead
Newbie
 
redhead's Avatar
 
Join Date: Jun 2002
Location: Denmark
Posts: 1,711
redhead is on a distinguished road
In order to fully understand recursion, look up recursion
__________________
Don't worry Ma'am, We're university students, We know what We're doing.
-----
If you pull the pin, Mr.Grenade would no longer be your friend.
-----
01000111 01101111 00100000 01000011 00100000 00100001
redhead is offline   Reply With Quote
Old 04-19-2008, 06:39 PM   #5 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,161
Belisarius is on a distinguished road
Recursion is calling a method or function from within itself. What was going on here was more akin to an anonymous declaration, but not because it wasn't anonymous. He was treating the internally declared class like it was being anonymously declared, which was part of the problem.
__________________
GitS
Belisarius is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Java Resources Belisarius Java 0 03-28-2005 02:03 PM
Java Developer Position in Kansas City justplaindoug Java 0 10-29-2004 11:52 AM
IBM urges Sun to make Java open source redhead Code Newbie News 0 03-01-2004 10:39 PM


All times are GMT -8. The time now is 10:05 AM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting