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

Doubt: K&B Self Test (Resolved and in errata)

 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
on page no 74(K&B book) there is question as follows.

A C and D is wrong.The book says B is correct but according to me the B is also wrong because there is no return type from speak method so this will not compile.

plz help
[ July 28, 2006: Message edited by: Barry Gaunt ]
 
Shiaber Shaam
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It has return type of type "Bark" ... So it is not wrong .....
 
Gowher Naik
Ranch Hand
Posts: 643
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what i want to say is that method doesnot return anything
 
Ramamoorthy Periasamy
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, The point here to understand is an abstract class can have non-abstract methods. NO need to check the code syntax unless its been asked explicitly
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think that this should be corrected because the question is asking for a compilable abstract class. If there is nothing returned in the body of the method it will not compile. So either return a Bark object or change return type to void. Hopefully Bert has already spotted this one before.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, it is in the K&B 5.0 errata (see link at top of SCJP forum).
 
d jones
Ranch Hand
Posts: 76
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could anyone please explain why Option A is not a compilable abstract class?


Thanks,
Dan
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by d jones:
Could anyone please explain why Option A is not a compilable abstract class?


Thanks,
Dan


Change the return type to void and the compiler will scream the reason at you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic