mirror of
https://github.com/Dichgrem/Java.git
synced 2025-12-16 20:42:00 -05:00
update:demo2
This commit is contained in:
44
com/study/demo2/Animal.java
Normal file
44
com/study/demo2/Animal.java
Normal file
@@ -0,0 +1,44 @@
|
||||
package com.study.demo2;
|
||||
|
||||
public abstract class Animal {
|
||||
protected String name;
|
||||
|
||||
public Animal(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public abstract void makeSound();
|
||||
public abstract void move();
|
||||
}
|
||||
|
||||
class Dog extends Animal {
|
||||
public Dog(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void makeSound() {
|
||||
System.out.println(name + " 汪汪叫");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move() {
|
||||
System.out.println(name + " 跑动");
|
||||
}
|
||||
}
|
||||
|
||||
class Bird extends Animal {
|
||||
public Bird(String name) {
|
||||
super(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void makeSound() {
|
||||
System.out.println(name + " 叽叽喳喳");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move() {
|
||||
System.out.println(name + " 飞翔");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user