This week's giveaway is in the Spring forum.
We're giving away four copies of Learn Spring Security (video course) and have Eugen Paraschiv on-line!
See this thread for details.
Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

inner class????

 
raymond yadao
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
according to jls:
It is a compile-time error if a local class declaration contains any one of the following access modifiers: public, protected, private, or static.
public class giant
{

private static class anotherClass
{
int i = 1000;
//System.out.println("this is an inner class");
}
public static void main(String args[])
{
anotherClass antClass = new giant().new anotherClass();
System.out.println(antClass.i);
}
}
why is this code compile and run?
thanks...
raymond
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
local class means a class defined within a method !
The following code is illegal !
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic