Read Java: The Good Parts
The type system
A pragmatic combination of features that provide an excellent tool.
- Interface is a way of building units of meaning that can be shared, extended, and explained
- An object is actually an instance of many types
- Every object in a Java program is an instance of a class.
- Only classes can be directly instantiated
- Interfaces play into the far more important use of the type system, which is to allow compile time checking of the arguments and return values passed to and returned from methods.
Single inheritance example,
public interface GraphicsObject{
Point getOrigin();
void setOrigin(Point newOrigin);
+ boolean draw(Point drawOrigin);
...
}
public interface Cowboy {
boolean ride(Horse toRide);
boolean rope(Cow toRope);
+ boolean draw(Point toShoot);
...
}
public class GraphicalCowboy implements GraphicsObject, Cowboy {
...
}
Since both the interfaces have draw()
signature we cannot have two difference implementations for the draw()
method.
Top comments (0)