File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes Static Inner Class Questions Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Static Inner Class Questions" Watch "Static Inner Class Questions" New topic

Static Inner Class Questions

Gary Farms
Ranch Hand

Joined: Jun 24, 2000
Posts: 57
When I compile the following program I get compile errors stating that StaticInnerClass can't be found. Also, the System.out.println generates a compile error also. Why? Can a static inner class have an argument list? Here's the program:
public class FinalTest
private static int staticvar=88;

public static void main(String[] args)
public static class StaticInnerClass
System.out.println("staticvar = " + staticvar);
Cindy Glass
"The Hood"

Joined: Sep 29, 2000
Posts: 8521
Try this:

The compiler was complaining about the "FinalTest.StaticInnerClass()" syntax without the new keyword.
The other complaint was having free floating executable code. Only variable declarations should be free floating, anything else should be in blocks or methods. When I put it in a constructor everything worked fine.

[This message has been edited by Cindy Glass (edited October 29, 2001).]

"JavaRanch, where the deer and the Certified play" - David O'Meara
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
A couple of things:
The error about StaticInnerClass can not be found is that the way you have the line written:
It is as if you're calling a static method of the FinalTest class called StaticInnerClass, if you're trying to create a new instance of the StaticInnerClass class then use this format:
StaticInnerClass sic = new Test.StaticInnerClass();
The other error your getting about the println statement is because the statement is not inside a block so it thinks you're declaring a new method. You need to put it in a block of code to make it work. Check this out:

hope that helps

Sun Certified Programmer for the Java� 2 Platform

I agree. Here's the link:
subject: Static Inner Class Questions
jQuery in Action, 3rd edition