| Author |
SCJP FAQ
|
Michael Angstadt
Ranch Hand
Joined: Jun 17, 2009
Posts: 272
|
|
One of the questions on the SCJP FAQ page[1] lists "some potential trips/traps in the SCJP exam". One trap reads:
No inner class can have a static member.
But this isn't true for static inner classes. For example, the following code compiles:
[1] http://faq.javaranch.com/java/ScjpFaq#tripsTraps
|
SCJP 6 || SCWCD 5
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24054
|
|
Hi Michael,
Static classes defined inside another class are called static nested classes, while non-static ones are called inner classes. Static nested classes can have static members, while inner classes cannot -- so the FAQ is correct as it stands. This is an important distinction to make. Sun's own documentation was sloppy on this at first but in recent years has been very clear.
|
[Jess in Action][AskingGoodQuestions]
|
 |
Devaka Cooray
Saloon Keeper
Joined: Jul 29, 2008
Posts: 2691
|
|
|
Well, to avoid this confusion I've made a little update on that FAQ.
|
Author of ExamLab (Download) - the free mock exam kit for SCJP / OCPJP
Home Page -- Twitter Profile -- JavaRanch FAQ -- How to Ask a Question
|
 |
Michael Angstadt
Ranch Hand
Joined: Jun 17, 2009
Posts: 272
|
|
Oh ok, thanks Ernest, wasn't aware of that.
I'm reading A Programmers Guide to Java SCJP Certification by Mughal and Rasmussen to prepare for the exam. The terms these authors use are "static member class" and "non-static member class".
|
 |
Ernest Friedman-Hill
author and iconoclast
Marshal
Joined: Jul 08, 2003
Posts: 24054
|
|
|
Those terms are not wrong, but they're also not the "official" terms, the ones that appear without explanation in Sun documentation, or on the exam. It definitely pays to know the official definitions.
|
 |
Mike Simmons
Ranch Hand
Joined: Mar 05, 2008
Posts: 2778
|
|
I disagree. The actual SCJP generally avoids such terminology in favor of examples. As for other documentation and definitions, "member class" is a well-defined term in the JLS (along with "member interface" and "member type" of course). And whether it's static or not is also well-defined. Err, maybe I should say it's strictly and unambiguously defined. Sun, in the past, made some poor choices as to how to communicate this stuff.
The term "static member class" means exactly the same thing as "static nested class" - if only because there's no such thing as a static nested class that is not also a member class. However the terms "inner class" and "non-static member class" are not the same thing - the latter is merely a subset of the former. The former also includes local and anonymous classes, while the latter does not. M&R use the term "non-static member classes" deliberately, for cases where they are not talking about local classes. The JLS refers to inner classes deliberately, for cases where they are including local classes. And when the JLS doesn't want to include local classes, they talk about "member classes", much like M&R.
Bottom line: each of these terms is well-defined by the most authoritative Sun sources (now). Some of these terms mean the same thing, and some mean different things. All of these terms are things that, in my opinion, a well-informed programmer should understand.
|
 |
 |
|
|
subject: SCJP FAQ
|
|
|