• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Member classes... book error?

 
Ranch Hand
Posts: 71
  • Mark post as helpful
  • send pies
  • 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
  • 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).]
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!