Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Yi Meng
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • 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 .....
 
Corey McGlone
Ranch Hand
Posts: 3271
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
That's the point........thanks Corey
 
Valentin Crettaz
Gold Digger
Sheriff
Posts: 7610
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving this to mock exam errata. Please continue the discussion there.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic