This week's book giveaway is in the JavaFX forum.
We're giving away four copies of Introducing JavaFX 8 Programming and have Herbert Schildt on-line!
See this thread for details.
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 Introducing JavaFX 8 Programming this week in the JavaFX forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Why This compiler error?" Watch "Why This compiler error?" New topic

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 = 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 = PixelOps.Inner();
mc.fn(dividend, divisor);
public class Inner
public void fn(int top, int bottom)
result = top / bottom;
System.out.println("result = " + result);
System.out.println("finally entered");
Paul Stevens
Ranch Hand

Joined: May 17, 2001
Posts: 2823
PixelOps.Inner mc = PixelOps.Inner();
PixelOps.Inner mc = Inner();
You already created a PixelOps (ec) so the new there wasn't needed.
I agree. Here's the link:
subject: Why This compiler error?
It's not a secret anymore!