• public class 类抽象类接口_练习 {
  • public static void main(String[] args) {
  • System.out.println("足球运动员的方法");
  • Foterbo foterbo = new Foterbo("海政",19,"足球运动员泡妞");
  • System.out.println("姓名:" + foterbo.getName() + "    " + "年龄:"
  • + foterbo.getAge() + "    " + "技能:"+foterbo.getJineng());
  • foterbo.sleep();
  • foterbo.student();
  • System.out.println();
  • System.out.println();
  • System.out.println();
  • System.out.println();
  • System.out.println("足球教练的方法");
  • Foterbojiaolian foterbojiaolian = new Foterbojiaolian();
  • foterbojiaolian.setName("李胖子");
  • foterbojiaolian.setAge(30);
  • System.out.println("姓名:" + foterbo.getName() + "    " + "年龄:"
  • + foterbo.getAge());
  • foterbojiaolian.sleep();
  • foterbojiaolian.speck();
  • }
  • }

  • interface English {
  • public abstract void speck();
  • }
  • abstract class Persons {
  • private String name;
  • public String getName() {
  • return name;
  • }
  • public void setName(String name) {
  • this.name = name;
  • }
  • public int getAge() {
  • return age;
  • }
  • public void setAge(int age) {
  • this.age = age;
  • }
  • public Persons() {
  • super();
  • }
  • public Persons(String name, int age) {
  • super();
  • this.name = name;
  • this.age = age;
  • }
  • private int age;
  • public abstract void sleep();
  • public void eat() {
  • System.out.println("吃饭");
  • }
  • }

  • abstract class Player extends Persons {
  • @Override
  • public void sleep() {
  • System.out.println("睡觉");
  • }
  • public Player() {
  • }
  • public Player(String name, int age) {
  • super(name, age);
  • }

  • public abstract void student();
  • }

  • class Foterbo extends Player {
  • public String getJineng() {
  • return jineng;
  • }

  • public void setJineng(String jineng) {
  • this.jineng = jineng;
  • }

  • private String jineng;

  • public Foterbo(String name, int age, String jineng) {
  • super(name, age);
  • this.jineng = jineng;
  • }

  • @Override
  • public void sleep() {
  • System.out.println("足球运动员躺着睡");
  • }

  • @Override
  • public void student() {
  • System.out.println("学习踢足球");
  • }

  • public Foterbo() {
  • }

  • }

  • class Foterbojiaolian extends Persons implements English {

  • @Override
  • public void speck() {
  • System.out.println("说英语");
  • }

  • @Override
  • public void sleep() {
  • // TODO 自动生成的方法存根
  • System.out.println("足球教练躺着睡");
  • }

  • public Foterbojiaolian() {

  • }

  • public Foterbojiaolian(String name, int age) {
  • super(name, age);
  • }
  • }
  • /* 
  •     假如我们在开发一个系统时需要对员工类进行设计,员工包含3个属性:姓名、工号以及工资。 
  •     经理也是员工,除了含有员工的属性外,另为还有一个奖金属性。 
  •     请使用继承的思想设计出员工类和经理类。要求类中提供必要的方法进行属性访问。 
  •      
  •     分析: 
  •         普通员工类 
  •             成员变量:姓名、工号以及工资。 
  •             成员方法:工作 
  •         经理类: 
  •             成员变量:姓名、工号以及工资,奖金属性 
  •             成员方法:工作 
  •              
  •     实现: 
  •         员工类: 
  •         普通员工类: 
  •         经理类: 
  • */  
  • 第二个小案例:
  • public class 抽象类继承多态_案例 {
  • public static void main(String[] args) {
  • System.out.println("普通员工的基本资料-----------------------");
  • Employee employee = new Putongyuangong();
  • employee.setName("海政");
  • employee.setAge(19);
  • employee.setId(2014130448);
  • employee.setMonny(100000);
  • System.out.println("姓名:" + employee.getName() + "   " + "年龄+"
  • + employee.getAge() + "   " + "学号+" + employee.getId() + "   "
  • + "工资+" + employee.getMonny());
  • employee = new Putongyuangong("黄海政", 20, 2014130448, 20000);
  • System.out.println("姓名:" + employee.getName() + "   " + "年龄+"
  • + employee.getAge() + "   " + "学号+" + employee.getId() + "   "
  • + "工资+" + employee.getMonny());
  • ((Putongyuangong) employee).work();
  • System.out.println();
  • System.out.println();
  • System.out.println();
  • System.out.println();
  • System.out.println("经理的基本资料---------------------------");
  • Jingli jingli = new Jingli();
  • jingli.setName("头头");
  • jingli.setAge(30);
  • jingli.setId(2013132023);
  • jingli.setMonny(1000000);
  • jingli.setJiangjin("陪领导打麻将");
  • System.out.println("姓名:" + jingli.getName() + "   " + "年龄+"
  • + jingli.getAge() + "   " + "学号+" + jingli.getId() + "   "
  • + "工资+" + jingli.getMonny() + "   " + "特殊能力:"
  • + jingli.getJiangjin());
  • jingli = new Jingli("头头", 30, 1013132023, 1000000, "陪领导打麻将");
  • System.out.println("姓名:" + jingli.getName() + "   " + "年龄+"
  • + jingli.getAge() + "   " + "学号+" + jingli.getId() + "   "
  • + "工资+" + jingli.getMonny() + "   " + "特殊能力:"
  • + jingli.getJiangjin());
  • jingli.work();
  • }
  • }
  • abstract class Employee {
  • private String name;
  • public Employee() {
  • super();
  • }
  • public Employee(String name, int age, int id, int monny) {
  • super();
  • this.name = name;
  • this.age = age;
  • this.id = id;
  • this.monny = monny;
  • }
  • public String getName() {
  • return name;
  • }
  • public void setName(String name) {
  • this.name = name;
  • }
  • public int getAge() {
  • return age;
  • }
  • public void setAge(int age) {
  • this.age = age;
  • }
  • public int getId() {
  • return id;
  • }
  • public void setId(int id) {
  • this.id = id;
  • }
  • public int getMonny() {
  • return monny;
  • }
  • public void setMonny(int monny) {
  • this.monny = monny;
  • }
  • private int age;
  • private int id;
  • private int monny;
  • }
  • class Putongyuangong extends Employee {
  • public Putongyuangong(String name, int age, int id, int monny) {
  • super(name, age, id, monny);
  • }
  • public Putongyuangong() {
  • }
  • public void work() {
  • System.out.println("上班咯~~~~~~~~~~~~~~~~");
  • }
  • }
  • class Jingli extends Employee {
  • private String jiangjin;
  • public String getJiangjin() {
  • return jiangjin;
  • }
  • public void setJiangjin(String jiangjin) {
  • this.jiangjin = jiangjin;
  • }
  • public Jingli(String name, int age, int id, int monny, String jiangjin) {
  • super(name, age, id, monny);
  • this.jiangjin = jiangjin;
  • }
  • public Jingli() {
  • // TODO 自动生成的构造函数存根
  • }
  • public void work() {
  • System.out.println("喝茶~~~~~~~~~~~~~~~~");
  • System.out.println("上班~~~~~~~~~~~~~~~~");类抽象类接口_练习
  • }
  • }

相关文章:

  • 2022-12-23
  • 2019-09-06
  • 2021-11-26
  • 2021-12-18
  • 2021-06-26
  • 2021-05-12
  • 2021-10-01
猜你喜欢
  • 2021-10-12
  • 2022-01-12
  • 2021-09-28
  • 2022-12-23
  • 2021-09-12
  • 2021-08-06
  • 2021-07-21
相关资源
相似解决方案