zoukankan      html  css  js  c++  java
  • java接口练习:看下图实现如下接口和类,并完成Adventure中的主方法。

    package pack1;
    
    public interface CanFly {
        void fly();
    
    }
    package pack1;
    
    public interface CanSwim {
        void swim();
    
    }
    package pack1;
    
    public class ActionCharacter {
        void fight(String emp)
    {

    }
    void speak(String s) { System.out.println(s); } }
    package pack1;
    
    public class Hero extends ActionCharacter implements CanSwim, CanFly {
        String name;
        
    
        public Hero(String name) {
            super();
            this.name = name;
        }
    
        @Override
        public void fly() {
            System.out.println(this.name+"会飞");
    
        }
    
        @Override
        public void swim() {
            System.out.println(this.name+"会游泳");
    
        }
    
        @Override
        void fight(String emp) {
            System.out.println(this.name+"打架很厉害");
    
        }
    
    }
    package pack1;
    
    public class Adventure {
    
        public static void main(String[] args) {
            Hero hb=new Hero("超人");
            hb.swim();
            hb.fly();
            hb.fight(null);
            CanFly cf=hb;
            cf.fly();
            CanSwim cs=hb;
            cs.swim();
            ActionCharacter ac=hb;
            ac.fight("超人");
            ac.speak("你好");
            
    
        }
    
    }
  • 相关阅读:
    第四章:(2)原理之 Dubbo 框架设计
    大三学习进度29
    大三学习进度27
    大三学习进度31
    大三学习进度24
    大三学习进度29
    大三学习进度26
    大三学习进度28
    大三学习进度25
    大三学习进度32
  • 原文地址:https://www.cnblogs.com/wallan/p/5523187.html
Copyright © 2011-2022 走看看