• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

question regarding modifiers applicable to top level class

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
When i was taking a mock exam there was a question as to
Which of the following modifiers are applicable to top level class
public
private
static
strictfp

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
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What happens when you compile a top level class with a modifier of private or static? Did you try that? If so, what messages did the compiler print, if any? Did the messages mean anything to you? It is absolutely essential that you try things out - learning Java programming is not only a theoretical process. There is a very important practical part that has to be learnt.
[ January 21, 2007: Message edited by: Barry Gaunt ]
 
Enthuware Software Support
Posts: 4906
60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Remember that a static nested class is also considered a Top Level class. So private and protected are also valid here.

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.
 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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!


Regards,

Amit Goyal
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I also beg to differ from Paul. The latest Java Language Specification states that a top level class is a non-nested class.

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.

It does not matter if the nested class is static or non-static.

So protected, static, private cannot be considered to be applicable to top-level classes.
[ January 22, 2007: Message edited by: Barry Gaunt ]
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[Paul Anil]: Remember that a static nested class is also considered a Top Level class.

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.
 
Paul Anilprem
Enthuware Software Support
Posts: 4906
60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey hey hey....don't gang up on me guys

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.

 
Paul Anilprem
Enthuware Software Support
Posts: 4906
60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jim Yingst:
[b]
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.
 
Sheriff
Posts: 11343
Mac Safari Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic