1 changed files with 31 additions and 0 deletions
@ -0,0 +1,31 @@ |
|||||
|
abstract class Animal{ |
||||
|
public abstract void makeSound(); |
||||
|
} |
||||
|
class Dog extends Animal implements Swimmable{ |
||||
|
@Override |
||||
|
public void makeSound(){ |
||||
|
System.out.println("woof"); |
||||
|
} |
||||
|
@Override |
||||
|
public void swim(){ |
||||
|
System.out.println("dog is swimming"); |
||||
|
} |
||||
|
} |
||||
|
class Cat extends Animal{ |
||||
|
public void makeSound(){ |
||||
|
System.out.println("miao"); |
||||
|
} |
||||
|
} |
||||
|
interface Swimmable{ |
||||
|
void swim(); |
||||
|
} |
||||
|
public class Main{ |
||||
|
public static void main(String[] args){ |
||||
|
Animal dog=new Dog(); |
||||
|
Animal cat=new Cat(); |
||||
|
Swimmable dog1=new Dog(); |
||||
|
dog.makeSound(); |
||||
|
dog1.swim(); |
||||
|
cat.makeSound(); |
||||
|
} |
||||
|
} |
||||
Loading…
Reference in new issue