• 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

K&B's CD Question...

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
Here is the question from K&B's CD:
class Bing {
Bing(String s) {};
Bing() {};
}
class Bang extends Bing {
Bang() {};
Bang(String bangS) {super(bangS);};
// inserted here
}
The question is which line can be inserted at // without produces error. One answer is
Bing b = new Bing() {"Foo";};
However, I am not understand why the above statement is OK. So I inserted this line and compile, following error is raised:
Bang.java:9: illegal start of type
Bing b = new Bing() {"Foo";};
^
Bang.java:9: <identifier> expected
Bing b = new Bing() {"Foo";};
^
2 errors
Why such error produced in compiling?
Thanks,
David
 
blacksmith
Posts: 979
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I wouldn't like to contradict Kathy or Bert ,
and see a spell cast on me now that I'm preparing
for the SCJP...
...but the answer doesn't look correct,
I can't compile it either, maybe it should have
been: Bing b = new Bing("Foo");
greetings,
Gian Franco
 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David,
From what you've posted it looks like a syntax error
As Gian has pointed out, it should either be
Bing b = new Bing("Foo");
or
Bing b = new Bing();
You may want to check their Errata page.

Cheers,
-Jarrod
 
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
True Jarrod ,
there seems to be syntax error...or mistype...
 
David Jones
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jarrod,
I did not find errata page related to this question. It seems that it is a typo now
David
 
reply
    Bookmark Topic Watch Topic
  • New Topic