File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Dog is not abstract and does not override abstract method

 
Bud Tippins
Ranch Hand
Posts: 52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm getting the following error when I try to run the code below in NetBeans:
Exception in thread "main" java.lang.ExceptionInInitializerError
at Practice16.main(Practice16.java:13)
Caused by: java.lang.RuntimeException: Uncompilable source code - Dog is not abstract and does not override abstract method compareTo(java.lang.Object) in java.lang.Comparable
at Dog.<clinit>(Practice16.java:3)

Any help in explaining why I am getting this error and how to resolve it would be much appreciated.

Thank you,


 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64194
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The compiler doesn't like being lied to. You told it that you will implement the java.lang.Comparable interface in Dog, but then you do not.
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problems is that Dog declares that it implements an interface, Comparable. But it doesn't implement the methods. So the solution is to implement the methods of the Comparable interface.

Small hint: you probably want Comparable<Dog> and when netbeans says that you have compilation error don't run the code.
 
Brian Enochson
Greenhorn
Posts: 14
Java Oracle Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bud,
You are getting this error because any class that implements the interface Comparable has to implement the method ;

Your compareTo method will return 1 of 3 values. 0 if the object passed in is equal to yours, 1 if your object is considered greater than the passed in object and -1 if it is less than. What you need to decide what is the criteria for the comparison. In your case, I would use size. Therefore your compareTo method might look like this:

 
Campbell Ritchie
Sheriff
Pie
Posts: 47293
52
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good answer, except a tiny disagreement with this bit:
Brian Enochson wrote: . . . Your compareTo method will return 1 of 3 values. 0 if the object passed in is equal to yours, 1 if your object is considered greater than the passed in object and -1 if it is less than. . . .
It returns a negative number if "less than", a positive number if "greater than" and 0 if "the same". 1, -1 and 0 are popular return values, but are not the only permissible values. It is commonly used in code like this
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic