zoukankan      html  css  js  c++  java
  • Java基础-接口看下图实现如下接口和类,并完成Adventure中的主方法

    package hanqi;
    
    public interface CanSwim {
    
        void swim();
    }
    package hanqi;
    
    public interface CanFly {
        
        public void fly();
    
    }
    package hanqi;
    
    public abstract class ActionCharacter {
    
          abstract void fight(String emp);
            
          abstract void speak(String s);
        
    }
    package hanqi;
    
    
    public class Hero  extends ActionCharacter implements CanFly, CanSwim{
    
         String name;
            Hero(String name)
            {
                this.name=name;
            }
    
            
            public void swim() {
                System.out.println(this.name+",游泳");
    
            }
    
    
            public void fly() {
                System.out.println(this.name+",飞");
    
            }
    
    
            void fight(String emp) {
                System.out.println(this.name+","+emp);
    
            }
    
    
            void speak(String s) {
                System.out.println(this.name+","+s);
    
        
    
            }
    }
    package hanqi;
    
    public class Adventure {
    
        public static void main(String[] args) {
            // TODO 自动生成的方法存根
            
            Hero hb = new Hero("A");
            hb.swim();
            hb.fight("B");
            hb.fly();
            
            CanFly cf = hb;
            hb.fly();
            
            CanSwim cs = hb;
            hb.swim();
            
            
            ActionCharacter ac = hb;
            ac.speak("C");
            ac.fight("D");
            
            
    
        }
    
    }

     

  • 相关阅读:
    Configuration Management
    Android Hooking
    技术趋势总结
    Maven Repo Mirror
    拥抱JAVA
    NPM 更新所有依赖项
    Knockout Mvc Compoment FrameSet With Typescript
    Knockoutjs Component问题汇总
    前端编码规范文档
    优秀程序设计的18大原则
  • 原文地址:https://www.cnblogs.com/zs6666/p/5911194.html
Copyright © 2011-2022 走看看