title: Java: Abstract classes methods and interface
body: <p>The program below calculates the total of the areas of any number of shapes instantiated. The problem is that I don't know how to output the <em>draw()</em> method of the interface.</p>
  
  <p>Here is the main class:</p>
  
  <pre><code>public class MyClass1{
  
  public static void main(String[] args) {
  
  
      Shape[] shapes= new Shape[3];
  
  
      shapes[0]= new Circle(20.0);
      shapes[1]= new Rectangle(25, 63);
      shapes[2]= new Circle(25);
  
     double total=0;
  
    for(int i=0; i&lt;shapes.length; i++){
  
      total+= shapes[i].area();
  
  }
  
  System.out.printf("Total: %.1f", total);
  
    }
  
   }
  </code></pre>
  
  <p>The superclass Shape </p>
  
  <pre><code> abstract class Shape {
  
    abstract double area();
  
  }
  </code></pre>
  
  <p>The interface Drawable</p>
  
  <pre><code>public interface Drawable {
      public abstract void draw();
  
  }
  </code></pre>
  
  <p>The subclass Circle</p>
  
  <pre><code>public class Circle extends Shape implements Drawable {
  
      double radius;
  
      Circle(double aRadius){
  
      radius= aRadius;
  }
  
  
     double area(){
  
         return Math.PI*radius*radius;
  }
  
      public void draw(){
         System.out.println("This is a circle");
    }
  
  }
  </code></pre>
  
  <p>The subclass Rectangle</p>
  
  <pre><code>  public class Rectangle extends Shape implements Drawable {
  
     double width, height;
  
     public Rectangle(double aWidth, double aHeight){
  
      width= aWidth;
      height= aHeight;
  
   }
  
      double area(){
  
         return width*height;
      }
  
     public void draw(){
  
         System.out.println("This is a rectangle.");
      }
    }
  </code></pre>
  
  <p>I assumed that to print out the draw() method,the code should be like this:</p>
  
  <pre><code>Shape obj= new Rectangle();
  Shape obj1= new Circle();
  
  obj.draw();
  obj1.draw();
  </code></pre>
  
  <p>But it's not working out. Would like to know the correct way to print the draw method along with some explanation since I am a newbie in Java.
  Thanks.</p>