An abstract method has no implementation. Or it might be
better to say that it has multiple implementations spread out over other
classes.
Abstract classes and interfaces contain abstract method
declarations.
One difference is that an interface only contains abstract
method declarations, while an abstract class may contain fields and concrete
(i.e., implemented) methods.
Another difference is that a class may implement many
interfaces but extends at most one class.
interface Movable {
void move(int x, int y);
}
interface Drawable {
void draw();
}
abstract class Shape {
int xc, yc, height, width;
abstract void draw();
void move(int x, int y) { xc = x; yc =
y; }
}
class Rectangle extends Shape implements Movable, Drawable {
void draw() {
// algorithm for drawing a rectangle
}
}
Here's the corresponding class diagram:
·
The names of abstract methods and classes are
italicized.
·
Why doesn't Rectangle need to implement move?