首页 >综合 > > 正文

Java.继承.super_每日报道

发布日期:2023-01-21 14:49:53 来源:哔哩哔哩 分享


(资料图)

1.main:

package project.ExtendsDay1.coder;public class main {    public static void main(String[] args) {        Coder c1=new Coder(21,"xiaoyu");        System.out.println(c1.getAge()+c1.getName());        c1.work();    }}

2.Employee:

package project.ExtendsDay1.coder;public class Employee {    public Employee(){    }    public Employee(int age,String name){        this.age=age;        this.name=name;    }    private int age;    private String name;    public void work(){        System.out.println("I'm huashui");    }    public int getAge() {        return age;    }    public void setAge(int age) {        this.age = age;    }    public String getName() {        return name;    }    public void setName(String name) {        this.name = name;    }}

3.Coder:

package project.ExtendsDay1.coder;public class Coder extends Employee {    public Coder(){}    public Coder(int age,String name){        super(age,name);    }    @Override    public void work(){        System.out.println("I'm coding\n"+super.getName()+" "+super.getAge()+"岁");    }}

标签: NAME SUPER STRING

Copyright ©  2015-2023 港澳兽药网版权所有  备案号:京ICP备2023022245号-31   联系邮箱:435 226 40 @qq.com