美文网首页
继承练习题2

继承练习题2

作者: 哈迪斯Java | 来源:发表于2021-10-31 14:22 被阅读0次

    package HspLearningExtend;

    public class PC extends ExerciseComputer {
    private String brand;

    //根据继承的规则,自动吧构造器的调用写好
    //体现了继承设计的基本思想,父类的构造器完成父类属性初始化
    //子类的构造器完成子类的属性初始化
    public PC(String cpu, int memory, int disk, String brand) {
        super(cpu, memory, disk);
        this.brand = brand;
    }
    
    public String getBrand() {
        return brand;
    }
    
    public void setBrand(String brand) {
        this.brand = brand;
    }
    
    public void printInfo() {
        System.out.println("PC的信息如下");
    

    // System.out.println(getCpu()+getMemory()+getDisk());
    //调用父类的getDetails
    System.out.println(getDetials() + " brand" + brand);
    }
    }

    package HspLearningExtend;

    public class PC extends ExerciseComputer {
    private String brand;

    //根据继承的规则,自动吧构造器的调用写好
    //体现了继承设计的基本思想,父类的构造器完成父类属性初始化
    //子类的构造器完成子类的属性初始化
    public PC(String cpu, int memory, int disk, String brand) {
        super(cpu, memory, disk);
        this.brand = brand;
    }
    
    public String getBrand() {
        return brand;
    }
    
    public void setBrand(String brand) {
        this.brand = brand;
    }
    
    public void printInfo() {
        System.out.println("PC的信息如下");
    

    // System.out.println(getCpu()+getMemory()+getDisk());
    //调用父类的getDetails
    System.out.println(getDetials() + " brand" + brand);
    }
    }

    package HspLearningExtend;

    public class Computer02 {
    public static void main(String[] args) {
    PC pc = new PC(" Intel",16,500," IBM");
    pc.printInfo();
    }
    }

    相关文章

      网友评论

          本文标题:继承练习题2

          本文链接:https://www.haomeiwen.com/subject/nxuoaltx.html