{
  "type": "code_options",
  "author": "csdn.net",
  "source": "solution.md",
  "exercise_id": "0120fa66c9424a8fb367615492018524",
  "keywords": "算法初阶,基础知识,算法基础,设计算法",
  "title": "设计学生类Student和它的一个子类Undergraduate",
  "desc": [
    {
      "content": "\n<p>设计一个学生类Student和它的一个子类Undergraduate&#xff0c;要求如下&#xff1a;\n(1)Student类有name和age属性&#xff0c;一个包含两个人参数的构造器&#xff0c;用于给两属性赋值&#xff0c;一个show()方法打印Student的属性信息。\n(2)本科生类Undergraduate增加一个degree(学位)属性。有一个包含三参数的构造器&#xff0c;前两个参数用于给集成的属性赋值&#xff0c;第三个参数给degree专业见值&#xff0c;一个show()方法用于打印Undergraduate的属性信息。\n(3)在测试类中分别打印Undergraduate和Student对象&#xff0c;调用它们的show()\n</p>",
      "language": "markdown"
    }
  ],
  "answer": [
    {
      "content": "",
      "language": "java"
    }
  ],
  "prepared": [
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ],
    [
      {
        "content": "",
        "language": "java"
      }
    ]
  ],
  "template": {
    "content": "package T1;\npublic class Test {\n\tpublic static void main(String[] args) {\n\t\tStudent stu = new Student(\"student\", 100);\n\t\tstu.show();\n\t\tUndergraduate undergraduate = new Undergraduate(\"Undergraduate\", 20, \"本科\");\n\t\tundergraduate.show();\n\t}\n}\nclass Student {\n\tprivate String name;\n\tprivate int age;\n\tpublic Student() {\n\t\tsuper();\n\t}\n\tpublic Student(String name, int age) {\n\t\tthis.name = name;\n\t\tthis.age = age;\n\t}\n\tpublic String getName() {\n\t\treturn name;\n\t}\n\tpublic void setName(String name) {\n\t\tthis.name = name;\n\t}\n\tpublic double getAge() {\n\t\treturn age;\n\t}\n\tpublic void setAge(int age) {\n\t\tthis.age = age;\n\t}\n\tpublic void show() {\n\t\tSystem.out.println(\"名字：\" + this.name + \"\\t年龄：\" + this.age);\n\t}\n}\nclass Undergraduate extends Student {\n\tprivate String degree;\n\tpublic Undergraduate(String name, int age, String degree) {\n\t\tsuper(name, age);\n\t\tthis.degree = degree;\n\t}\n\tpublic void show() {\n\t\tSystem.out.println(\"名字：\" + super.getName() + \"\\t年龄：\" + super.getAge() + \"\\t学位:\" + this.degree);\n\t}\n}",
    "language": "java"
  },
  "node_id": "dailycode-0eb0d6cdc41643e89bb5683c139216bb",
  "license": "csdn.net",
  "created_at": 1637894160,
  "topic_link": "https://bbs.csdn.net/topics/600470293"
}