• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SCJP FAQ

 
Ranch Hand
Posts: 282
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Sheriff
Posts: 7134
1360
IntelliJ IDE jQuery Eclipse IDE Postgres Database Tomcat Server Chrome Google App Engine
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, to avoid this confusion I've made a little update on that FAQ.
 
Michael Angstadt
Ranch Hand
Posts: 282
Eclipse IDE PHP Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Master Rancher
Posts: 4796
72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic