This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes what is the answer Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "what is the answer " Watch "what is the answer " New topic
Author

what is the answer

nikunj thakur
Ranch Hand

Joined: Sep 23, 2007
Posts: 47
why is this not a compilable abstract class

public abstract class Canine { public Bark speak();}
Nik Arora
Ranch Hand

Joined: Apr 26, 2007
Posts: 652
Hi Nikunj,

Originally posted by nikunj thakur:
why is this not a compilable abstract class

public abstract class Canine { public Bark speak();}


An abstract class should have abstract methods and can have non-abstract method also.In your example the method is not abstract so you are getting the error.

Regards,
Nik
Yogesh Baraskar
Ranch Hand

Joined: Oct 07, 2007
Posts: 33
public abstract class Canine { public Bark speak();}

speak(); // the brackets and then semicolon suggests that it is an abstract method and you should declare it as
public abstract Bark speak();

or else if you dont want to declare method as abstract then make it
public Bark speak(){
}
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: what is the answer
 
Similar Threads
abstract method overriding
need packages help
regarding class definition
classes cannot be marked as protected?????
Abstract class - Whetehere sub class should implement all the abstract methods of base class ?