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.
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 .....
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.
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