Eric said:
Dear all:
I can't figure out the difference between Interfaces and class on java.
Interfaces are the highest level of abstraction, they define what an object
of that type can do, but not how it does it.
The next level is an abstract class, these partially define behaviour and
leave some methods to be defined by subclasses.
Concrete classes are the lowest level, and only these can be instantiated.
The hierachy can be put together as such
interface Cutter {
void cut();
void sharpen();
}
abstract class Knife implements Cutter
abstract public void cut();
public void sharpen() {
// apply whetstone
}
}
class Penknife extends Knife {
public void cut() {
// do some whittling etc
}
}
Typically having the above structure you would then do something like this:
Cutter cutter = new Penknife();
By passing references to Cutter about one can ensure maximum generallity and
if ever you need to change the Concrete implementation it is simply a case
of changing the code at the point of instantiation.