[Template design mode]

Source: Internet
Author: User
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 ("Step 1 method of demo1");} public void step2 () {system. out. println ("Step 1 method of demo1");} public void Step3 () {system. out. println ("Step 1 method of demo1");} class demo2 extends model {public void Step1 () {system. out. println ("Step 1 method of demo2");} public void step2 () {system. out. println ("Step 1 method of demo2");} public void Step3 () {system. out. println ("Step 1 method of demo2") ;}} class test {public static void main (string [] ARGs) {demo1 d1 = new demo1 (); demo2 D2 = new demo2 (); system. out. println ("START instance 1's template-specific method:"); d1.model _ function (); system. out. println ("START instance 2's template-specific method:"); d2.model _ function ();}}

 

 

Running result:

Start instance 1's template-specific method: demo1's 1st step method demo1's 2nd step method demo1's 3rd step method finished! Start instance 2's template-specific method: demo2's Step 1 method demo2's Step 2 method demo2's Step 2 method finished!

 

[Template design mode]

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.