my dog learned polymorphism*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes  Local Class Declarations Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark " Local Class Declarations" Watch " Local Class Declarations" New topic
Author

Local Class Declarations

Manish Kumar
Ranch Hand

Joined: Apr 15, 2002
Posts: 53
Hi,
I found the following in JLS section 14.3
"It is a compile-time error if a local class declaration contains any one of the following access modifiers: public, protected, private, or static."
But when I compiled this code it did not show any error.
class Test{
private class Test2{}

}
Please help me.
Valentin Crettaz
Gold Digger
Sheriff

Joined: Aug 26, 2001
Posts: 7610
A local class is a class enclosed within a method or an initializer block.
I'd like you to read the Javaranch Naming Policy and change your publicly displayed name to comply with our unique rule. Thank you.
[ April 15, 2002: Message edited by: Valentin Crettaz ]

SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
Manish Kumar
Ranch Hand

Joined: Apr 15, 2002
Posts: 53
Thanks Crettaz
But is there any difference between local classes and inner classes?
Jim Bedenbaugh
Ranch Hand

Joined: Nov 09, 2001
Posts: 171
Originally posted by Manish K:
Thanks Crettaz
But is there any difference between local classes and inner classes?

Put the inner class inside a method and try to compile it. Let us know what happens.


Regards,
Jim
SCJP, SCJD, SCWCD, SCEA Part I
Dave Vick
Ranch Hand

Joined: May 10, 2001
Posts: 3244
Manish
From the JLS section 8.1.2:
"An inner class is a nested class that is not explicitly or implicitly declared static."
And, from the JLS section 14.3:
"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."
hope that clears it up for you


Dave
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Local Class Declarations