Abstract Class and Interface

http://cdncontribute.geeksforgeeks.org/wp-content/uploads/Abstract-Class-vs-Interface.png

Abstract

//abstract parent class
abstract class Animal{
   //abstract method
   public abstract void sound();
}
//Dog class extends Animal class
public class Dog extends Animal{

   public void sound(){
    System.out.println("Woof");
   }
   public static void main(String args[]){
    Animal obj = new Dog();
    obj.sound();
   }
}

interface

interface MyInterface
{
   /* compiler will treat them as: 
    * public abstract void method1();
    * public abstract void method2();
    */
   public void method1();
   public void method2();
}
class Demo implements MyInterface
{
   /* This class must have to implement both the abstract methods
    * else you will get compilation error
    */
   public void method1()
   {
    System.out.println("implementation of method1");
   }
   public void method2()
   {
    System.out.println("implementation of method2");
   }
   public static void main(String arg[])
   {
    MyInterface obj = new Demo();
    obj.method1();
   }
}

※参考 beginnersbook.com www.geeksforgeeks.org