*
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 Android Security Essentials Live Lessons this week in the Android 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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why This compiler error?
 
Similar Threads
Can you tell what is wrong with this loop?
When is Stacktrace printed in Exceptions?
InnerClass
static variables - Please help!
Member classes... book error?