标签:style blog io color ar sp div on log
package package8; abstract class Model{ public void model_function(){ step1(); step2(); step3(); System.out.println("Finished!"); } public abstract void step1(); public abstract void step2(); public abstract void step3(); } class Demo1 extends Model{ public void step1(){ System.out.println("Demo1的第1步方法"); } public void step2(){ System.out.println("Demo1的第2步方法"); } public void step3(){ System.out.println("Demo1的第3步方法"); } } class Demo2 extends Model{ public void step1(){ System.out.println("Demo2的第1步方法"); } public void step2(){ System.out.println("Demo2的第2步方法"); } public void step3(){ System.out.println("Demo2的第3步方法"); } } class Test{ public static void main(String[] args){ Demo1 d1=new Demo1(); Demo2 d2=new Demo2(); System.out.println("开始实例1对于模板的特有方法:"); d1.model_function(); System.out.println("开始实例2对于模板的特有方法:"); d2.model_function(); } }
运行结果:
标签:style blog io color ar sp div on log
原文地址:http://www.cnblogs.com/balfish/p/4065497.html