aspose file tools*
The moose likes Beginning Java and the fly likes Why This compiler error? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why This compiler error?" Watch "Why This compiler error?" New topic
Author

Why This compiler error?

Gary Farms
Ranch Hand

Joined: Jun 24, 2000
Posts: 57
The following program contains a member inner class called Inner which contains a method called fn. I call it from main in the enclosing class PixelOps.
When I compile it, I get a compile error: stating that a '(' is expected on the following line: PixelOps.Inner mc = ec.new PixelOps.Inner(); Why do I get this? Also, does a member inner class always have to be declared public?
Here's the short program:
public class PixelOps
{
static int result;
public static void main(String[] args)
{
int dividend = 100;
int divisor;
divisor = 0;
PixelOps ec = new PixelOps();
PixelOps.Inner mc = ec.new PixelOps.Inner();
mc.fn(dividend, divisor);
}
public class Inner
{
public void fn(int top, int bottom)
{
try
{
result = top / bottom;
System.out.println("result = " + result);
}
finally
{
System.out.println("finally entered");
}
}
}
}
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
Change
PixelOps.Inner mc = ec.new PixelOps.Inner();
to
PixelOps.Inner mc = ec.new Inner();
You already created a PixelOps (ec) so the new there wasn't needed.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Why This compiler error?