You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
572 B
31 lines
572 B
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();
|
|
}
|
|
}
|