抽象方法《Thinking in Java》随笔014
AbstractFather类:
1 package cn.skyfffire; 2 3 public abstract class AbstractFather { 4 public abstract int getFive(); 5 }
AbstractSon类:
1 package cn.skyfffire; 2 3 public abstract class AbstractSon extends AbstractFather { 4 5 }
Test:
1 package cn.skyfffire; 2 3 /** 4 * 5 * @author skyfffire 6 * 7 */ 8 public class Test { 9 public static void main(String[] args) { 10 AbstractFather a = new AbstractFather() { 11 public int getFive() { 12 return 5; 13 } 14 }; 15 16 a.getFive(); 17 } 18 }
1.要么在匿名类里实现抽象方法
2.要么在子类里实现抽象方法
3.要么将子类声明为抽象方法,待子类的子孙类来实现