title: Creating an object with a different reference type and instance type
body: <p>How can I improve the program implementation? The program failed when tested with reference type as the interface and instance type as the implementation classes . Concentrate on creating an object with a different reference type and instance type.</p>
  
  <pre><code>package com;
  interface Shape {
  public abstract double getArea(double d);
  }
  public class TestCircle {
  public static void main(String[] args) {
  
      Circle s = new Circle();
      System.out.println(s.getArea(5));
      System.out.println(calculateArea(s,5));
      Shape s1 = new Square();
      System.out.println(calculateArea(s1,5));
  }
  public static double calculateArea(Shape s, double d){
      if(s==null) return 0.0;
      return s.getArea(d);
  }
  }
  class Circle implements Shape{
  public double getArea(double d){
      if(d&lt;0) return 0.0;
      return d*d*(22.0/7);
  }
  }
  class Square implements Shape{
  public double getArea(double d){
      //if(d&lt;0)   return 0.0;
      return d*d;
  }
  }
  </code></pre>