Hi friends,
This is a question from Self
Test of Chapter 2: "Declarations and Access Control" of Kathy Sierra Book. I understand that a non nested class cannot be marked protected as rightly pointed out in this example. However when it is said...�Nonnested classes cannot be marked protected (
or final for that matter),� what does it mean? Can�t outer classes be marked final?? Then why is it that I don�t get a compiler error when trying to do so? did I get the meaning of the sentence wrong ??? i'm confused !
8. Given the following,
1. import java.util.*;
2. public class NewTreeSet2 extends NewTreeSet {
3. public static void main(
String [] args) {
4. NewTreeSet2 t = new NewTreeSet2();
5. t.count();
6. }
7. }
8. protected class NewTreeSet {
9. void count() {
10. for (int x = 0; x < 7; x++,x++ ) {
11. System.out.print(" " + x);
12. }
13. }
14. }
what is the result?
A. 0 2 4
B. 0 2 4 6
C. Compilation fails at line 4
D. Compilation fails at line 5
E. Compilation fails at line 8
F. Compilation fails at line 10
Answer 8. _ E. Nonnested classes cannot be marked protected (or final for that matter), so the
compiler will fail at line 8.
_ A, B, C, and D are incorrect because of the explanation given above.
[ August 20, 2007: Message edited by: Radhika ]