Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

types of classes and class access

 
Jasper Vader
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
is a local class a class that is defined in a method?
is a nested class a class defined within an enclosing class?
is a top level class not enclosed by a method or a class?
public and package are the modifiers available to top level or local classes; public, package, protected and private are available to nested classes?
 
Ilja Preuss
author
Sheriff
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All correct, except that I don't think local classes do have access modifiers. Could be wrong, though...
 
Dirk Schreckmann
Sheriff
Posts: 7023
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note that a local class doesn't have to be defined in a method block. A local class can be defined in any block.
From The JLS
A local class is a nested class (�8) that is not a member of any class and that has a name. All local classes are inner classes (�8.1.2). Every local class declaration statement is immediately contained by a block.
...
The scope of a local class declared in a block is the rest of the immediately enclosing block, including its own class declaration.
A local class cannot be preceded by an access modifier. Nothing declared in a block can.
[ January 31, 2003: Message edited by: Dirk Schreckmann ]
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic