This week's giveaway is in the Testing forum.
We're giving away four copies of TDD for a Shopping Website LiveProject and have Steven Solomon on-line!
See this thread for details.
Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Possibly wrong answer given for question 25 in Trial exam from javacertificate

 
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which of the folowing statements are correct? [Check all correct answers]


1. public static native methodName();
2. private protected class newClass{};
3. private transient Integer counter = new Integer(0);
4. private volatile int number;
5. protected static class newClass{};
The answer given is 3&4, but
No. 5 should be correct when it is used to define inner class .....
 
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yup, you're right. Take a look at the JLS, §8.1.1 Class Modifiers and you'll see the following:


A class declaration may include class modifiers.
ClassModifiers:
ClassModifier
ClassModifiers ClassModifier
ClassModifier: one of
public protected private
abstract static final strictfp
Not all modifiers are applicable to all kinds of class declarations. The access modifier public pertains only to top level classes (�7.6) and to member classes (�8.5, �9.5), and is discussed in �6.6, �8.5 and �9.5. The access modifiers protected and private pertain only to member classes within a directly enclosing class declaration (�8.5) and are discussed in �8.5.1. The access modifier static pertains only to member classes (�8.5, �9.5). A compile-time error occurs if the same modifier appears more than once in a class declaration.
If two or more class modifiers appear in a class declaration, then it is customary, though not required, that they appear in the order consistent with that shown above in the production for ClassModifier.

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

Originally posted by Yi Meng:
No. 5 should be correct when it is used to define inner class .....


On a side note (and a rather picky one at that), if the declaration read "protected static class...", this is not an inner class. Inner classes are nested classes that are not declared static. If it was declared as static, it is simply a nested class, not an inner class.
Corey
 
Yi Meng
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That's the point........thanks Corey
 
Author & Gold Digger
Posts: 7617
6
IntelliJ IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving this to mock exam errata. Please continue the discussion there.
 
Weeds: because mother nature refuses to be your personal bitch. But this tiny ad is willing:
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic