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

Question on Abstract Class

 
marthi reddy
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Source is from K & B Certification book chapter 1 question - 2

Which declase a compilable abstract class ?

a) public abstract class Canine { public Bark speak(); }
b) public abstract class Canine { public Bark Speak() {} }
c) public class Canine { public abstract Bark speak(); }
d) public class Canine abstract { public abstract Bark speak();}

I understand that options a,c and d based on the definition for abstract of a class and method. But the book is saying that answer is option b. Abstract classes don't have to have any abstract methods.

But my question is still the code is not compilable because the method defined in the class is not having a return statement when it is expecting one. So my answer will be None of the options are correct. Am I correct?
 
Brian Legg
Ranch Hand
Posts: 488
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm no expert but I would agree with you. If the method declares that it will return a Bark and the method just has open/close brackets and no return statement it would not compile.

What version of the book do you have because mine does not have that question in it?
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Marthi! Welcome to Javaranch.

I think this is a possible error. Or the authors might have focused more on logic behind the program and might have missed to write something like return null or //some code in the method bodies...
 
Sherif Shehab
Ranch Hand
Posts: 485
Android Eclipse IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi pals,

Check this for more infos about abstract class.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic