• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Doubt - Dan Chisholm's Inner classes

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Which of the follow class declarations results in a compiler error?
The answer is 3,4,5,6,7,8,9
My Doubt:
I tried compiling this code and the error comes out as 2,3,5,7,8,9. However the Java 2 Certification guide by Heller & Simon's say that "Classes declared in methods are private to the method and cannot be marked with any access modifier;neither can they be marked static".
Can someone tell me what access modifiers are allowed for classes
1.that are nested inner classes (member classes)
2.inner classes within methods.
[Dan added UBB codes to format the code block.]
[ March 21, 2003: Message edited by: Dan Chisholm ]
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Here are a couple sources that should help you out. If you still have questions after reading these, let me know.
JLS §8.1.2 Inner Classes and Enclosing Instances
Campfire Story
I hope that helps,
Corey
 
Ranch Hand
Posts: 1865
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Priya Venkatesan:

Can someone tell me what access modifiers are allowed for classes
1.that are nested inner classes (member classes)
2.inner classes within methods.


The modifiers that can be used with a nested class are: abstract, final, private, protected, public, static, strictfp.

The modifiers that can be used to declare a class that is local to a method are: abstract, final, strictfp. The access modifiers, public, protected and private, can not be used to declare a class that is local to a method.
For more information, please see section 8.1.1 of the Java Language Specification.
 
Lasagna is spaghetti flvored cake. Just like this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic