File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Beginning Java and the fly likes types of classes and class access Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "types of classes and class access" Watch "types of classes and class access" New topic

types of classes and class access

Jasper Vader
Ranch Hand

Joined: Jan 10, 2003
Posts: 284
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?

giddee up
Ilja Preuss

Joined: Jul 11, 2001
Posts: 14112
All correct, except that I don't think local classes do have access modifiers. Could be wrong, though...

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - Heraclitus
Dirk Schreckmann

Joined: Dec 10, 2001
Posts: 7023
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 ]

[How To Ask Good Questions] [JavaRanch FAQ Wiki] [JavaRanch Radio]
I agree. Here's the link:
subject: types of classes and class access
It's not a secret anymore!