It's not a secret anymore!
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Question on Abstract Class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Question on Abstract Class" Watch "Question on Abstract Class" New topic

Question on Abstract Class

marthi reddy

Joined: Oct 27, 2008
Posts: 6
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?

I belive in "Judge your Java concepts by taking SCJP exam". <br /> <br />Happy preparation for SCJP 6.0
Brian Legg
Ranch Hand

Joined: Nov 07, 2008
Posts: 488
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?

~Currently preparing for SCJP6
Ankit Garg

Joined: Aug 03, 2008
Posts: 9465

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...

SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
Sherif Shehab
Ranch Hand

Joined: Mar 05, 2007
Posts: 484

Hi pals,

Check this for more infos about abstract class.

I agree. Here's the link:
subject: Question on Abstract Class
It's not a secret anymore!