1 interface InterfaceOne
  2 {
  3 	void sayHello();
  4 }
  5 /*接口之间要用extends关键字
  6 interface InterfaceTwo implements interfaceOne
  7 {
  8 
  9 }*/
 10 interface InterfaceThree extends InterfaceOne
 11 {
 12 }
 13 //抽象类可以不用实现接口或父抽象类的方法。
 14 abstract class AbstractClassOne implements InterfaceOne
 15 {
 16 }
 17 abstract class AbstractClassTwo extends AbstractClassOne
 18 {
 19 }
 20 //非抽象类一定要实现接口内的方法。
 21 class ClassOne implements InterfaceOne
 22 {
 23 	public void sayHello() {};
 24 }

如果遇到一个接口中需要实现的方法很多,但我们只需要用其中的几个方法,
假设需要继承的接口是:

  1 interface A
  2 {
  3 	void operation1();
  4 	void operation2();
  5 	……
  6 	void operation100();
  7 }

假设我们只需要使用其中的operation5
如果直接继承这个接口,则所有方法都要实现:

  1 class Class implements A
  2 {
  3 	public void operation1(){}
  4 	public void operation2(){}
  5 	……
  6 	public void operation5(){
  7 		/*
  8 		 * operation5
  9 		 */
 10 	}
 11 	……
 12 	public void operation100(){}
 13 }

这样十分麻烦,所以可以使用如下方法解决,
新建一个抽象类(如果规定一个接口方法一定要实现,则把它设为抽象方法,比如说operation99必须要实现):

  1 abstract class Abstract implements A
  2 {
  3 	public void operation1(){}
  4 	public void operation2(){}
  5 	……
  6 	public void operation98(){}
  7 	//这里的operation99就不提供虚实现,从而必须要在具体类中实现它。
  8 	public void operation100(){}
  9 }

为所有接口方法提供一个虚实现,今后要利用这个接口只需要进行如下操作:

  1 class Class extends Abstract
  2 {
  3 	//重写operation5
  4 	public void operation5(){
  5 		/*
  6 		 * operation5
  7 		 */
  8 	}
  9 	//实现operation99
 10 	public void operation99(){
 11 		/*
 12 		 * operation99
 13 		 */
 14 	}
 15 }

这样就不必为每个接口方法提供实现了。