• 2020.8.18


    学习内容

     1、研究生继承

    复制代码
     1 public class Student2 {
     2     protected int num;
     3     protected String name;
     4     protected char sex;
     5     Student2(){}
     6     public void setValue(int n,String str,char c) {
     7         num=n;
     8         name=str;
     9         sex=c;
    10     }
    11     public void display() {
    12         System.out.println("学号:"+num+"\t 姓名:"+name+"\t 性别:"+sex);
    13     }
    14 }
    15 public class Postgraduent1 extends Student2 {
    16     private String advisor;
    17     Postgraduent1(){}
    18     public void setAdvisor(String str) {
    19         advisor=str;
    20     }
    21     public static void main(String[] args) {
    22         Postgraduent1 xq=new Postgraduent1();
    23         xq.setValue(1122, "Xiao Qiang", 'M');
    24         xq.setAdvisor("Prof.Zhu");
    25         xq.display();
    26         System.out.println("Advisor:"+xq.advisor);
    27     }
    28 }
    复制代码

         

     2.研究生继承2

    复制代码
     1 //父类:学生类
     2 public class Student2 {
     3     protected int num;
     4     protected String name;
     5     protected char sex;
     6     Student2(){}
     7     Student2(int n,String str,char c) {
     8         num=n;
     9         name=str;
    10         sex=c;
    11     }
    12     public void display() {
    13         System.out.println("学号:"+num+"\t姓名:"+name+"\t 性别:"+sex);
    14     }
    15 }
    16 //子类:研究生类
    17 public class Postgraduent1 extends Student2 {
    18     private String advisor;
    19     Postgraduent1(){}
    20     Postgraduent1(int n,String s,char c,String str){
    21         super(n,s,c);
    22         advisor=str;
    23     }
    24     public static void main(String[] args) {
    25         Postgraduent1 xq=new Postgraduent1(10001, "小明", 'M',"Prof.Zhu");
    26         xq.display();
    27         System.out.println("Advisor:"+xq.advisor);
    28     }
    29 }
    复制代码

       

  • 相关阅读:
    web应用本质
    SQL逻辑查询语句执行顺序
    flask-WTForms组件
    生产者消费者模型
    单例模式
    flask中的信号量
    flask-script
    flask-session
    在python项目中导出项目依赖的模块信息
    Flask简介之简单应用
  • 原文地址:https://www.cnblogs.com/ltw222/p/14151373.html
Copyright © 2020-2023  润新知