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.

26 lines
685 B

public class Fish extends Animal {
private double swimSpeed; // Special attribute: swimming speed
public Fish(String name, int age, double swimSpeed) {
super(name, age);
this.swimSpeed = swimSpeed;
}
public double getSwimSpeed() {
return swimSpeed;
}
public void setSwimSpeed(double swimSpeed) {
this.swimSpeed = swimSpeed;
}
@Override
public void makeSound() {
System.out.println(getName() + " makes bubble sounds: Blub! Blub!");
}
// Special method: swimming
public void swim() {
System.out.println(getName() + " is swimming at " + swimSpeed + " km/h.");
}
}