Modeling: define class. User-defined type or reference type. 

Class is container of static members also contains a blueprint.

Blueprint contains instance members and is a vision. 

Instantiate the blueprint to get objects, instances. 

Constructors come into play when you instantiate objects. 

class Point {
  private int x, y; 
  Point() {
    this(0, 0); 
  }
  Point(int x, int y) {
    this.x = x;
    this.y = y;
  } 
  public String toString() {
    return "Point at (" + this.x + ", " + this.y + ")"; 
  }
  public double distanceTo(Point other) {
    int dx = this.x - other.x;
    int dy = this.y - other.y;
    double distance = Math.sqrt( dx * dx + dy * dy ); 
    return distance; 
  }
  public static void main(String[] args) {
    Point a = new Point(2, 3); 
    System.out.println( a ); 
    System.out.println( a.distanceTo( new Point(3, 2) ); 
  }
}

Class extension mechanism: set union of features.

Horse = { ... }

Unicorn = Horse U { horn }

Every class extends java.lang.Object

java.lang.Object has a method called toString() simple but useful.

Every class extends and inherits from Object. 

By defining your own toString() method you are doing: overriding. 

Overriding creates the phenomenon known as dynamic method lookup. 

Assume Horse has talk() that talks in English. 

class Shape implements Comparable<Shape> {
  public int compareTo(Shape other) {
    ... 
  }
}

Assume that Unicorn extends Horse: it inherits talk

But now I redefine talk in Unicorn. 

If Unicorn also defines sing() do we have a problem?

Things we have:

Horse a = new Unicorn(); // polymorphism 

Unicorn b = new Unicorn(); // normal 

Horse c = new Horse(); // normal 

Unicorn d = new Horse(); // bad 

a.talk(); // works by inheritance

a.sing(); // it will not because a is of type Horse 

((Unicorn)a).sing(); // this will work though by casting 

Now if we redefine talk() in Unicorn (French) dynamic method lookup 
happens and it means the following: 

(a) if Horse x = new Unicorn(); 

(b) then I can ask for x.talk(); // sure by inheritance

(c) except it will be class Unicorn that determines the type of talk()

So Unicorns will only speak in French if you ask them.

From inside they can still access English, with super.talk()

abstract class Shape {
  int x, y;
  Shape(int x, int y) {
    this.x = x; 
    this.y = y; 
  }
  abstract double area(); 
}

class Circle extends Shape {
  int radius; 
  Circle(int x, int y, int r) {
    super(x, y); 
    this.radius = r;     
  }   
  double area() {
    return Math.PI * this.radius * this.radius;
  }
}


interface Shape {
  public double area(); 
}

class Circle implements Shape {
  ... // constructor and instance 
  public double area(0 {
    ... 
  } 
}