- interface Person
- {
- void eat();
- }
- class Chinese implements Person
- {
- public void eat()
- {
- System.out.println("吃饭");
- }
- public void show()//Chinese类的特性方法
- {
- System.out.println("我是中国人");
- }
- }
- class Show
- {
- public static void main(String[] args)
- {
- Person p = new Chinese();
- p.eat();
-
- Chinese c = (Chinese)p;//p向下转型
- if(p instanceof Person)//此处有一个判断
- c.show();
- }
- }
复制代码
额 ,上面代码没显示出来- -ll |