DEV Community

Janardhan Pulivarthi
Janardhan Pulivarthi

Posted on • Updated on

Day 19 of 100 - Java: the good parts book read

Read Java: The Good Parts

The type system

A pragmatic combination of features that provide an excellent tool.

  1. Interface is a way of building units of meaning that can be shared, extended, and explained
  2. An object is actually an instance of many types
  3. Every object in a Java program is an instance of a class.
  4. Only classes can be directly instantiated
  5. 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 {
Enter fullscreen mode Exit fullscreen mode

Since both the interfaces have draw() signature we cannot have two difference implementations for the draw() method.

Top comments (0)