This week's book giveaway is in the Java in General forum.
We're giving away four copies of Event Streams in Action and have Alexander Dean & Valentin Crettaz on-line!
See this thread for details.
Win a copy of Event Streams in Action this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Knute Snortum
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Ron McLeod
  • Piet Souris
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Frits Walraven
  • Ganesh Patekar

Why This compiler error?

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
}
}
}
}
 
Ranch Hand
Posts: 2823
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!