• 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

Quirk in Rule Round-up and comment

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am running NT 4.00.1381 and Netscapr 4.6. Occasionally the question does not display (the cows and radio buttons display fine). Hitting reload once (or twice) gets the questioned to display.
Comment on question 232: TRUE or FALSE: an inner class has free access to ALL member data of its enclosing (outer) class.
Since it was not specified that the inner class was a non-static, non-local inner class I would think the answer would be false (the round-up answer is true). Should the wording of this question be changed to reflect that the inner class is non-static and non-local?
Thanks.
BTW, the site is really cool.
 
Trailboss
Posts: 23778
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are some known bugs with the applet. I have it pulled apart at home although it will probably be a week or more until I can fix it.
Question 232: TRUE or FALSE: an inner class has free access to ALL member data of its enclosing (outer) class.
Answer: TRUE. An inner class has a special relationship and can see even private member data of the outer class.
By non-local I take it you are talking about classes within a method?
I see your point about static inner classes. This question is definitely ambiguous.
Maybe the question should be changed to "a static inner class has free access to ALL member data of its enclosing (outer) class." and then the answer will be false.
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Paul Wheaton:

By non-local I take it you are talking about classes within a method?
I see your point about static inner classes. This question is definitely ambiguous.
Maybe the question should be changed to "a static inner class has free access to ALL member data of its enclosing (outer) class." and then the answer will be false.


I use the term "local" to indicate that the inner class is declared/used in a method of the enclosing class. In this case the inner class can only access variables/parameters that have been declared final in the enclosing class.
Your proposed change in wording would certainly work. You could also add "non-static" and then the answer would remain true.
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul- "By non-local I take it you are talking about classes within a method?"
I would assume that non-local means classes outside a method. It is unnecessary to specify this though. Local classes (which includes anonymous classes) have access to all member data of the enclosing class, so for them the answer is TRUE, just as it is for all non-static member classes. These are the only classes properly called inner classes, but thanks to some unfortunate inconsistency from Sun, "static inner" classes are sometimes considered "inner" classes as well. They should be called top-level nested, or static nested, or static member (new term from JLS 2nd Ed). In any event they should not be considered inner, but since there is widespread confusion about this perhaps it would be best to clarify this point in the question:
TRUE or FALSE: an inner class (not including a top-level nested class) has free access to ALL member data of its enclosing (outer) class.
Answer: TRUE.
Or you could change it to only ask about TLNCs as you suggest, but I like this one better. There is a widespread myth (illustrated by Mr. Wetherbie above - sorry John) that a local class can't access member fields of the outer class unless they're final. It's true local classes can't access a local variable of the enclosing method (or code block) unless it's final - but that has nothing to do with member variables. Keeping the question along its original intent catches the people who think this, and hopefully they learn.
[This message has been edited by Jim Yingst (edited April 05, 2000).]
 
paul wheaton
Trailboss
Posts: 23778
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jim,
Oops! Slipped a negative in there.
I think one thing we need to remember about the questions in the roudup game is that they have to be short (due to real estate restraints) and they can't be giving the answer away. If you have a lot of conditions in your question, one can guess that the answer is true.
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good point. How about
TRUE or FALSE: a non-static nested class has free access to ALL member data of its enclosing (outer) class.
Or, a "non-static inner class" works also, though it's technically redundant. But given the widespread confusion Sun has caused on this point, redundancy is a good thing.
 
paul wheaton
Trailboss
Posts: 23778
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Done.
I also added the word "always" because test takers think "always" questions are false.
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oooh, devious...
 
John, Wetherbie
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hey, thanks for clearing this "myth" up for me! Of course, I didn't know it was a myth. The certification book I am using has this to say:
"Because local inner classes are defined local to a code block (like a local variable), they may only access the local variables or method parameters of the code block in which they are defined. An additional restriction is placed on local inner classes in that they may only access variables or parameters that are declared as final and have been assigned a value."
(p 146, Java 2 Certification, J. Jaworski)
It's possible that I am misinterpretting this...
As far as the term "static inner" class goes, it is misleading. Static member class may help (still seems misleading). How about top-level nested static class?
Jim - thanks for clearing up my confusion on inner classes inside a method (or scope block) or whatever you want to call them.
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It doesn't sound like you're misinterpreting - from what you've quoted, Jaworski is just plain wrong here. Does anyone know of an errata list for Jaworski? If not, that's an much bigger mark against Jaworski than the original error, IMO. RHE, Brogden, and Mughal/Rasmussen all keep errata (RHE's seems unusally long, but at least they have one ).
Yeah, I don't really like "static inner" (can you tell?) but it seems to have caught on. Probably because most of the literature emphasized "inner" instead of "nested", people are more familiar with the former term. And the specs only mention as an afterthought that a nested class that's static isn't inner, but rather top-level. Also people like to have short terms for things - "static inner" is much shorter than "top-level nested", and comes closer to describing what one actually looks like. "Static nested" would have worked as well, but it wasn't the term the spec writers went with. Ah well... However:
It looks like the JLS 2nd edition will in fact use "static member class" in place of "top-level nested class". "Top-level" goes back to meaning really top-level, i.e. not nested. However the definition of "inner" is not changing - a non-static member class is an inner class, but a static member class is not. So that particular religious war will still go on, but those of us on the side of truth and light will have shiny new ammo.
Hmmm... a non-static member variable is also known as an instance variable, and a static member variable is also known as a class variable. By extension, the respective nested class equivalents could be known as an "instance class" and a "class class" respectively. Surely that would clear up the confusion.
 
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The book has a URL that is supposed to have errata. The page is there but there is no errata. I also went out to the publisher's (New Riders) site and the page that might have the errata is down for reconstruction.
More interesting is that I can't find any mention of Jaworski's book at the New Riders site.
 
paul wheaton
Trailboss
Posts: 23778
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I say "fire up the compiler and make sure!"
 
John Wetherbie
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Paul, you're right on this point. It always pays to test things out with code. So, that's what I did last night to check this issue out.
 
paul wheaton
Trailboss
Posts: 23778
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
And?
 
John Wetherbie
Rancher
Posts: 1449
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jim was right on the money.
 
paul wheaton
Trailboss
Posts: 23778
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jim, I hereby DOUBLE YOUR SALARY!
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Golly, that probably puts me in a higher tax bracket now.
 
paul wheaton
Trailboss
Posts: 23778
IntelliJ IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I may be a bit shaky in my math, but isn't zero times two equal to zero?
 
Jim Yingst
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Party pooper.
 
It's just a flesh wound! Or a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic