抽象父类
public abstract class Cooking {
/**
* 定义算法骨架
*/
public final void make(){
System.out.println("开始准备工作");
prepare();
System.out.println("开始做菜");
cook();
}
public abstract void prepare();
public abstract void cook();
}
实现子类
public class MakeFish extends Cooking{
@Override
public void prepare() {
System.out.println("杀鱼,清洗");
}
@Override
public void cook() {
System.out.println("开蒸");
}
}
调用
public class MakeTest {
public static void main(String[] args) {
Cooking cooking = new MakeFish();
cooking.make();
}
}