• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Traps to be aware of in any SCJP test !!!!! :)

 
Jeff L.
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are static inner classes referred to sometimes as nested top-level classes? I think it is just silly semantics. Someone probably, realized once that the below two code fragments would have exactly the same implementation if you pretend that the latter is a legal name. I can see the reasoning now: "Since in the implementation of an inner static class, the binary code doesn't need a pointer to an instance of the outer class, maybe we shouldn't call an inner static class inner at all, but rather nested top-level."
Fortunately, wiser heads prevailed and they mostly abandoned the semantic quibble, rather than pushing a confusing, yet meaningless to non-language-implementers, distinction.
below:
class outer {
static class inner {
}}
class outer {}
static class outer.inner {}
 
Jeff L.
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oops again.
Final local variables cannot be initialized once, so from the perspective of local variables, what I said was true.
Final member variables behave differently. You can't initialize them on first use, but what you can do is initialize them in each constructor, rather than initializing them inline. Therefore I misspoke when I said the initialization had to be during declaration.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic