Which of the following modifiers are applicable to top level class
can any one please tell me the correct answer i selected public but the answer says public and strictfp...the top level class can have default or public access modifier only right...can strictfp be applied to the top level class...
sorry for troubling you with a simple question as im new to java and have just started to prepare for scjp
[ January 21, 2007: Message edited by: Barry Gaunt ]
The term "Top Level class" is now kind of deprecated. There is now class, inner class (aka non-static nested class), and static nested class.
The term "class" is too generic. It includes all, inner classes,anonymous classes and top level nested classes(static nested class).
For static inner class one can use the term "static nested class" or "Top level nested class".
If I am wrong pls correct me!
It does not matter if the nested class is static or non-static.
A nested class is any class whose declaration occurs within the body of another class or interface. A top level class is a class that is not a nested class.
So protected, static, private cannot be considered to be applicable to top-level classes.
[ January 22, 2007: Message edited by: Barry Gaunt ]
You're using ancient terminology. Yes, Sun did once invent the horrible, evil term "top-level nested class" but they got rid of it long ago. (JLS 2nd edition was released in 2000.) Bringing it up now just confuses people. In modern usage (since 2000), classes are either top-level or nested, never both.
[Paul Anil]: The term "Top Level class" is now kind of deprecated.
Not at all. The term now means exactly what anyone would expect it to mean, if they had never heard of Sun's silly "top-level nested class" notion (which should be excised from memory like a bad dream). A top level class is simply a class that's not nested.
Fortunately, the SCJP exam does not care whether people know this terminology or not.
The following is from Sun's tutorial page : http://java.sun.com/docs/books/tutorial/java/javaOO/nested.html
Terminology: Nested classes are divided into two categories: static and non-static. Nested classes that are declared static are simply called static nested classes. Non-static nested classes are called inner classes.
Regarding static nested class -
Note: A static nested class interacts with the instance members of its outer class (and other classes) just like any other top-level class. In effect, a static nested class is behaviorally a top-level class that has been nested in another top-level class for packaging convenience.
Originally posted by Jim Yingst:
A top level class is simply a class that's not nested.
You guys are right. JLS says this clearly in 8.1.3 ( http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.1.3 ). Thanks for correcting me.
They still have made a distinction between an inner-class and a nested class.
Originally posted by Jim Yingst:
... Yes, Sun did once invent the horrible, evil term "top-level nested class" but they got rid of it long ago...
Unfortunately, it's kind of like legacy code that never really gets fixed. As Paul illustrated with the Java Tutorial quote, this term is still floating out there in some prominent places.
girl power ... turns out to be about a hundred watts. But they seriuosly don't like being connected to the grid. Tiny ad:
Thread Boost - a very different sort of advertisinghttps://coderanch.com/t/674455/Thread-Boost-feature