Template mode (exam questions reuse)

Source: Internet
Author: User
Package COM. template;/*** Test Questions and Answers * @ filefile: examepaper. java * @ version: 1.0 * @ Author: sky * @ Date: 2012-7-4 * ===================================== * @ package: COM. template * @ class: * @ extend *** =====================================================* Copyright (c) 2012 colavia */public class examepaper {public void question1 () {system. out. println ("1 + 1 =? A: 0 B:-1 C: 4 D: 2 "); system. out. println ("Answer:" + answer1 ();} public void question2 () {system. out. println ("1 + 3 =? A: 0 B:-1 C: 4 D: 2 "); system. out. println ("Answer:" + answer2 ();} public void question3 () {system. out. println ("1 + 2 =? A: 3 B:-1 C: 4 D: 2 "); system. out. println ("Answer:" + answer3 ();} public void question4 () {system. out. println ("9 + 1 =? A: 0 B: 10 C: 4 D: 2 "); system. out. println ("Answer:" + answer4 ();} Public String answer1 () {return "" ;}; Public String answer2 () {return "";}; public String answer3 () {return "" ;}; Public String answer4 () {return "";};}

Package COM. template;/*** answer to the first question * @ filefile: testpaper1.java * @ version: 1.0 * @ Author: sky * @ Date: 2012-7-4 * ===================================== * @ package: COM. template * @ class: * @ extend *** =====================================================* Copyright (c) 2012 colavia */public class testpaper1 extends examepaper {@ overridepublic string answer1 () {return "A" ;}@ overridepublic string answer2 () {return "C ";} @ overridepublic string answer3 () {return "D" ;}@ overridepublic string answer4 () {return "";}}

Package COM. template;/*** answer to the second question * @ filefile: testpaper2.java * @ version: 1.0 * @ Author: sky * @ Date: 2012-7-4 * ===================================== * @ package: COM. template * @ class: * @ extend *** =====================================================* Copyright (c) 2012 colavia */public class testpaper2 extends examepaper {@ overridepublic string answer1 () {return "D" ;}@ overridepublic string answer2 () {return "";} @ overridepublic string answer3 () {return "C" ;}@ overridepublic string answer4 () {return "B ";}}

Package com. template;/*** the simulation method moves the unchanged behavior to the superclass, removing repeated code in the subclass to reflect its advantages. * The simulation method is a good code reuse platform * @ filefile: mainrun. java * @ version: 1.0 * @ Author: sky * @ Date: 2012-7-4 * ===================================== * @ package: COM. template * @ class: * @ extend *** =====================================================* Copyright (c) 2012 colavia */public class mainrun {/*** @ Param ARGs */public static void main (string [] ARGs) {examepaper paper1 = new testpaper1 (); paper1.question1 (); paper1.question2 (); paper1.question3 (); system. out. println ("===================="); examepaper paper2 = new testpaper2 (); paper2.question1 (); paper2.question2 (); paper2.question3 ();}}

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.