• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

SCJP FAQ

 
Michael Angstadt
Ranch Hand
Posts: 277
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

 
Devaka Cooray
ExamLab Creator
Marshal
Pie
Posts: 4330
238
Chrome Eclipse IDE Google App Engine IntelliJ IDE jQuery Postgres Database Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, to avoid this confusion I've made a little update on that FAQ.
 
Michael Angstadt
Ranch Hand
Posts: 277
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 24208
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3041
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic