1. // 题目和答案分开来
    2. public abstract class TestPaper {
    3. public void question1() {
    4. System.out.println("第一道题目");
    5. System.out.println("答案:"+Answer1());
    6. }
    7. protected abstract String Answer1() ;
    8. public void question2() {
    9. System.out.println("第二道题目");
    10. System.out.println("答案:"+Answer2());
    11. }
    12. protected abstract String Answer2() ;
    13. public void question3() {
    14. System.out.println("第三道题目");
    15. System.out.println("答案:"+Answer3());
    16. }
    17. protected abstract String Answer3() ;
    18. }
    19. public class TestPaperA extends TestPaper {
    20. @Override
    21. protected String Answer3() {
    22. return "a";
    23. }
    24. @Override
    25. protected String Answer1() {
    26. return "b";
    27. }
    28. @Override
    29. protected String Answer2() {
    30. return "c";
    31. }
    32. }
    33. public class TestPaperB extends TestPaper {
    34. @Override
    35. protected String Answer3() {
    36. return "e";
    37. }
    38. @Override
    39. protected String Answer1() {
    40. return "f";
    41. }
    42. @Override
    43. protected String Answer2() {
    44. return "g";
    45. }
    46. }
    47. public class Test {
    48. public static void main(String[] args) {
    49. TestPaper testPaperA =new TestPaperA();
    50. TestPaper testPaperB =new TestPaperB();
    51. testPaperA.question1();
    52. testPaperA.question2();
    53. testPaperA.question3();
    54. testPaperB.question1();
    55. testPaperB.question2();
    56. testPaperB.question3();
    57. }
    58. }