Compare commits
2 Commits
59e76ecfeb
...
20e0ff3e31
| Author | SHA1 | Date |
|---|---|---|
|
|
20e0ff3e31 | 5 days ago |
|
|
94cdc9f719 | 6 days ago |
1 changed files with 34 additions and 0 deletions
@ -0,0 +1,34 @@ |
|||||
|
abstract class Animal { |
||||
|
public abstract void makesound(); |
||||
|
} |
||||
|
interface Swimmable{ |
||||
|
void swim(); |
||||
|
} |
||||
|
class Dog extends Animal implements Swimmable{ |
||||
|
@Override |
||||
|
public void makesound(){ |
||||
|
System.out.println("汪汪汪"); |
||||
|
} |
||||
|
@Override |
||||
|
public void swim(){ |
||||
|
System.out.println("狗刨游泳"); |
||||
|
} |
||||
|
} |
||||
|
class Cat extends Animal{ |
||||
|
@Override |
||||
|
public void makesound(){ |
||||
|
System.out.println("喵喵喵"); |
||||
|
} |
||||
|
} |
||||
|
class Main{ |
||||
|
public static void main(String[]args){ |
||||
|
Animal a =new Dog(); |
||||
|
Animal b =new Cat(); |
||||
|
a.makesound(); |
||||
|
b.makesound(); |
||||
|
if (a instanceof Swimmable){ |
||||
|
((Swimmable)a).swim(); |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
Loading…
Reference in new issue