/*** Advanced abstract class ** @ author administrator **/public abstract class abstractclass {public static final string method_1 = "M1"; public static final string method_2 = "m2 "; public final void templatemethod (string methodname) {If (method_1.equals (methodname) {dooperation1 (methodname);} If (method_2.equals (methodname) {dooperation2 (methodname );}} protected abstract void dooperation1 (string methodname); protected abstract void dooperation2 (string methodname );}
/*** This class inherits the advanced abstract class * @ author administrator **/public class concreteclass extends abstractclass {@ overrideprotected void dooperation1 (string methodname) {system. out. println (methodname) ;}@ overrideprotected void dooperation2 (string methodname) {system. out. println (methodname );}}
Result Display:
In the template method mode, the calling of abstract methods is not controlled by the subclass, but is reversed to the parent class to control its calling. This also becomes a reversal of the direction...