18 lines
460 B
Java
18 lines
460 B
Java
|
// make the class cat inherit from Animal
|
||
|
public class Cat extends Animal {
|
||
|
// java requires an explicit constructor when the supertype awaits parameters in the constructor
|
||
|
public Cat(String name) {
|
||
|
// call supertype constructor
|
||
|
super(name);
|
||
|
}
|
||
|
|
||
|
// override make_sound
|
||
|
public void make_sound() {
|
||
|
// optional: call the parent class function
|
||
|
super.make_sound();
|
||
|
|
||
|
// add additional functionality
|
||
|
System.out.println("meow");
|
||
|
}
|
||
|
}
|