(资料图)
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()+"岁"); }}
Copyright © 2015-2023 港澳兽药网版权所有 备案号:京ICP备2023022245号-31 联系邮箱:435 226 40 @qq.com