PDA

View Full Version : Abstract classes implementing comparable




Mac Player
Mar 2, 2007, 04:53 PM
Hi,

Can i implement comparable in an abstract class? This way for example, i could sort of array of objects from different clsses extending the same abstract class. Or maybe not.....



Llywelyn
Mar 2, 2007, 05:05 PM
Hi,

Can i implement comparable in an abstract class? This way for example, i could sort of array of objects from different clsses extending the same abstract class. Or maybe not.....

I assume you mean in Java?

Yes. You can implement a Comparable abstract class. You can also implement a Comparable interface.

Mac Player
Mar 2, 2007, 05:10 PM
Thanks. Yes I was talking about java.

So i can do something like:

public abstract class xxx implements Comparable

kpua
Mar 2, 2007, 07:28 PM
Quickest way to find out is to experiment for yourself...

Llywelyn
Mar 2, 2007, 07:55 PM
Thanks. Yes I was talking about java.

So i can do something like:

public abstract class xxx implements Comparable

Basically yes, but use generics ~_^

Why not just try it and see?