Big talk Design Pattern _ template method pattern

Source: Internet
Author: User

Take students as an example.

Package COM. WZS. design;/*** big talk design mode -- page93 template method mode ** @ author administrator **/public class templatemethod {public static void main (string [] ARGs) {testpapera = new testpapera (); testpapera. answer1 (); testpapera. answer2 (); testpapera. answer3 (); system. out. println (); testpaperb = new testpaperb (); testpaperb. answer1 (); testpaperb. answer2 (); testpaperb. answer3 () ;}/ ** exam */abstract class testpaper {// first question public void testquestion1 () {system. out. println ("1. (). confucius B. mencius C. chuang Tzu D. left Qiu Ming ");} // public void testquestion2 () {system. out. println ("2. mr. Lee's book by customer was chosen from (). zuo Chuan B. historical records C. warring States policy D. mandarin ");} // Question 3 Public void testquestion3 () {system. out. println ("3. in the preface to the five generations of history, the warning statement that warns people to think about danger is (). evil often accumulates in the micro, Chi Yong mostly trapped in B. all losses, benefits ");} // answer to the first question public abstract void answer1 (); // answer to the second question public abstract void answer2 (); // Answer to Question 3 public abstract void answer3 ();}/** student a exam */class testpapera extends testpaper {public void answer1 () {system. out. println ("A");} public void answer2 () {system. out. println ("B");} public void answer3 () {system. out. println ("C") ;}/ ** student B exam */class testpaperb extends testpaper {public void answer1 () {system. out. println ("B");} public void answer2 () {system. out. println ("C");} public void answer3 () {system. out. println ("D ");}}

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.