• 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

Member classes... book error?

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm using a combination of books to study for the SCJP exam. I'm particularly concerned about the following example instantating member classes:

This will not compile. Lines 3 and 4 of TestEC.java are taken straight from the book, given as a valid example, SCJP Study Guide by Global Knowlegde Certification Press/Syngress/Osborne, pg. 260, Chapter 8: Inner Classes.
( www.syngress.com is inaccessible at the moment so I cannot determine if there is a note regarding errata in the book. )
However, the above syntax on line 4 is noted as incorrect in Java in a Nutshell, 3rd Ed.. Can anyone comment on this? What I have working is the following, based on JIAN and other sources:



[This message has been edited by Timothy Stone (edited October 09, 2001).]
 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

The code won't compile as expected, since the syntax to instantiate an inner class is:
Primary.new Identifier(ArgumentList...)
(From InnerClass Specification p.19)
As you can see, after the new operator is an Identifier,
which does not allow "."
So, the line 4 will fail for sure.
The reason is since an enclosing object
reference is already provided before the new operator,there
is no need to repeat the enclosing class type after the new operator. You only need to specify the inner class after
the new operator.
Java in a NutShell is correct.
[This message has been edited by Marilyn deQueiroz (edited October 10, 2001).]
[This message has been edited by Nain Hwu (edited October 10, 2001).]
 
What do you have in that there bucket? It wouldn't be a tiny ad by any chance ...
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic