Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Top-Level class

 
Aarti Joshi
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1) What is a top level class ? Can top level class be declared protected/private ?
--cheers
Aarti
 
Jessica Sant
Sheriff
Posts: 4313
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Top Level class is any normal Java class, it can only be declared public or default (aka package).
like this:
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Definition: A nested class is any class whose declaration occurs within the body of another class or interface.
Definition: A top level class is a class that is not a nested class.
 
Kathy Sierra
Cowgirl and Author
Rancher
Posts: 1589
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Howdy -- just wanted to add that there *is* some confusion (some of which I am responsible for) about the terminology because the JLS and Gosling's "The Java Programming Language" conflict. Gosling mentions that a static nested class is also known as a "Top Level Nested Class", but as Marlene pointed out , the spec clearly says that in order to be a Top Level class the class must NOT be nested. So, two documents Gosling has authored conflict with each another.
That's one of the few little 'issues' we have at Sun, because we're allowed to use just about anything Gosling says for the exam, as opposed to JUST the JLS, even though 90% of the exam wording now reflects the specification. The SCJP is also supposed to be about certifying working programmers, so we try to strike a balance between formal specification language and 'common use', as long as 'common use' isn't completely wrong or misleading. Well, in this case, many of us at Sun have been using the phrase "top level nested class" long enough ot have it burned into our heads. I'm in the process of removing it from mine right now. Ouch!
It used to be worse... the SCJP used to use the phrase "static inner class". Yikes! That was *never* correct, but in casual language, that's how we often talked about it.
I'm trying to work out if there are any other issues like that -- where there's a conflict between the spec and other Sun documents that might be used when we build the exam. I haven't found any that matter. And in fact, even this "top-level/static/nested" terminology won't hurt you on the exam. As long as you can identify in code exactly how they work, you won't be tripped up by what they're called.
Cheers!
Kathy
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kathy, thank you for sharing in detail your insider's view.
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have noticed in books and in forum discussions, some people use the word "visible" when they mean "accessible". The JLS has two definitions, one for accessible, another for visible.
 
Marlene Miller
Ranch Hand
Posts: 1392
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Kathy, if the exams use definitions different from the JLS for top-level, nested, inner and static classes, I request that the terms and their meanings be published with the Objectives.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic