首页 > 代码库 > 0923-----In class to practive
0923-----In class to practive
1 package com.kai.li; 2 3 /** 4 * 5 */ 6 public class FlyText{ 7 public static void main(String[] args){ 8 Plane p = new Plane(); 9 Bird b = new Bird();10 makeFly(p);11 makeFly(b);12 makeFly("dddkkdkdk");13 makeFly(20.5);14 makeFly(new Object());15 }16 public static void makeFly(Object o){17 if(!(o instanceof ICanFly))18 System.out.println("I can‘t fly.");19 else 20 ((ICanFly)o).fly();21 }22 }
1 package com.kai.li;2 /**3 * 4 */5 public interface ICanFly{6 void fly();7 }
1 package com.kai.li; 2 3 /** 4 * 5 */ 6 public class Plane implements ICanFly{ 7 public void fly(){ 8 System.out.println("I am a plane,I can fly."); 9 }10 }
1 package com.kai.li; 2 3 /** 4 * 5 */ 6 public class Bird implements ICanFly{ 7 @Override 8 public void fly(){ 9 System.out.println("I am a bird,I can fly.");10 }11 }
0923-----In class to practive
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。