• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

What is a top level class?

 
javamiller
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is it simply a class which can be inherited?
 
sgwbutcher
Ranch Hand
Posts: 56
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A top-level class is any class that is not an inner class or nested class, a class whose definition is not enclosed within another class that can live by itself in a source file, the class having unmodified (no keyword) or public access.
I'm not sure what you mean by "a class that can be inherited" because the only classes that can be inherited are classes defined inside classes (i.e., not top-level classes).
If you mean a class at the top of the inheritance hierarchy or a branch thereof (like Object, Throwable, orObjectEvent) then "no." But then I'm pretty sure whatever you mean the answer might be "no" but I'd be curious to know what you meant.
Best regards,
Steve Butcher
exceptionraised@aol.com
 
javamiller
Greenhorn
Posts: 14
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A class that could be inherited, I mean, a class that is extendable, or a class that could be a super class of another class.
So the answer to my question is NO. Since final class could be
a "top level" class but it is not extendable.
I am wondering if "top level class" an official term. I have
seen "nested top level class". Does it mean only a static
inner class or any kind of inner class.
Thanks.
 
Anonymous
Ranch Hand
Posts: 18944
  • 0
  • send pies
  • Quote
  • Report post to moderator
>I'm not sure what you mean by "a class that can be
>inherited" because the only classes that can be
>inherited are classes defined inside classes (i.e.,
>not top-level classes).

Every time I think I understand all this, I read something that confuses me again. You can only extend a top level class, right?
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dave001- no, you can extend any class as long as it's not final.
As for the original question - under the original specifications for nested classes, there is no such thing as a static inner class. The thing that everyone keeps calling a static inner class was properly called a top-level nested class. This term was used to make people aware that TLNC's had more in common with regular top-level classes than with other nested classes. (Mostly, the fact that you could instantiate them without bothering to instantiate the enclosing class first.) But the term never caught on, and in the JLS 2nd edition TLNC's are being called "static member" classes instead - they're still not properly considered inner classes, but they're not top-level either. However, people will probably continue to ignore this and talk about "static inner" classes anyway.
So, the meaning of these terms unfortunately depends on who's talking. You're probably safest assuming that someone talking about "top-level" classes does not mean to include static member classes unless they mention them specifically. If someone mentions "inner" classes, they could well mean to include static member classes as well even though that's technically incorrect. If they actually say the phrase "static inner class" (which you may see on the exam), you know that, even though it's wrong, they do mean to refer to static member classes.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic