首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

标识形式

2012-09-06 
标识模式package com.identitypublic class Animal {}package com.identitypublic class Cat extends An

标识模式

package com.identity;public class Animal {}package com.identity;public class Cat extends Animal{}package com.identity;import static com.identity.Food.*;//静态属性的引入public class Feeder {public void feed(Animal animal,Food food){System.out.println(animal.getClass().getName()+" eat "+food.getClass().getName());}public static void main(String[] args){new Feeder().feed(new Cat(), new Fish());System.out.println(price);}}package com.identity;public class Fish extends Animal implements Food{}package com.identity;//food接口只是作为动物可以做为食物的属性,没有别的内容//在food中也可以定义很多的常量,当外部希望可以使用常量的时候,可以直接方位//另外在jdk1.5提供了import static 的语句public interface Food {public static final double price=1;}

热点排行