| Author |
Possibly wrong answer given for question 25 in Trial exam from javacertificate
|
Yi Meng
Ranch Hand
Joined: May 07, 2003
Posts: 270
|
|
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 .....
|
Meng Yi
|
 |
Corey McGlone
Ranch Hand
Joined: Dec 20, 2001
Posts: 3271
|
|
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.
|
SCJP Tipline, etc.
|
 |
Corey McGlone
Ranch Hand
Joined: Dec 20, 2001
Posts: 3271
|
|
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
Joined: May 07, 2003
Posts: 270
|
|
|
That's the point........thanks Corey
|
 |
Valentin Crettaz
Gold Digger
Sheriff
Joined: Aug 26, 2001
Posts: 7610
|
|
|
Moving this to mock exam errata. Please continue the discussion there.
|
SCJP 5, SCJD, SCBCD, SCWCD, SCDJWS, IBM XML
[Blog] [Blogroll] [My Reviews] My Linked In
|
 |
 |
|
|
subject: Possibly wrong answer given for question 25 in Trial exam from javacertificate
|
|
|