This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

K&B's CD Question...

 
David Jones
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • 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
 
Gian Franco
blacksmith
Ranch Hand
Posts: 979
  • Mark post as helpful
  • send pies
  • 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
 
Jarrod Legion
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • 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
 
Raja Sagar Panamgipalli
Ranch Hand
Posts: 109
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic