This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Java Interview Guide and have Anthony DePalma on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes nested classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "nested classes" Watch "nested classes" New topic

nested classes

Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Is the following statement
1) true or
2) false?
"a nested top-level class cannot declassre any static variables, static methods, or static initializers."
can somebody decipher this for me?
paul wheaton

Joined: Dec 14, 1998
Posts: 20973

How can it be nested and top level at the same time?
Well, whatever craziness is happening there, I would have to say the method is false because inner classes can have static stuff too. (although I've never tried it, I'm pretty sure they can)
Anyone tried compiling this?

permaculture Wood Burning Stoves 2.0 - 4-DVD set
Tony Alicea

Joined: Jan 30, 2000
Posts: 3226
"How can it be nested and top level at the same time?"
I read that you have Peter van der Linden's Just Java 2? Could you check page 235, Table 9-1?
This nomenclature has driven more people than myself crazy before...!

Tony Alicea
Senior Java Web Application Developer, SCPJ2, SCWCD
Jim Yingst

Joined: Jan 30, 2000
Posts: 18671
Heck, "top-level nested" is fine. It's when they talk about "static inner" classes that the arguments start.
A top-level nested class is Sun's official term for what is often called a static inner class (or static nested, which is better really), e.g.

As you can see, it can declare static methods and variables, as well as non-static (not shown).

"I'm not back." - Bill Harding, Twister
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
The reason I posted this question is that I got this question in one of the mock tests
I agree. Here's the link:
subject: nested classes
It's not a secret anymore!