// Define the interface Animal with two abstract methods for makeSound()
interface Animal {
void makeSound(String whatistheSound);
void makeSound(String whatistheSound, int loudness);
}
class Tiger implements Animal {
// Implementation of the first makeSound method
public void makeSound(String sound) {
System.out.println("Tiger says " + sound);
}
// Overloaded method implementation
public void makeSound(String sound, int loudness) {
System.out.println("Tiger says " + sound + " at " + loudness + " decibels");
}
}
class Monkey implements Animal {
// Implementation of the first makeSound method
public void makeSound(String sound) {
System.out.println("Monkey says " + sound);
}
// Overloaded method implementation
public void makeSound(String sound, int loudness) {
System.out.println("Monkey says " + sound + " at " + loudness + " decibels");
}
}
public class Main {
public static void main(String[] args) {
Animal myAnimal;
myAnimal = new Tiger();
myAnimal.makeSound("Growl"); // Calls the first method
myAnimal.makeSound("Growl", 80); // Calls the overloaded method
myAnimal = new Monkey();
myAnimal.makeSound("Cheep Cheep"); // Calls the first method
myAnimal.makeSound("Cheep Cheep", 50); // Calls the overloaded method
}
}
interface Animal {
void makeSound(String whatistheSound);
void makeSound(String whatistheSound, int loudness);
}
class Tiger implements Animal {
public void makeSound(String sound) {
System.out.println("Tiger says " + sound);
}
// This class chooses not to implement the overloaded makeSound method with two parameters
}
class Monkey implements Animal {
public void makeSound(String sound) {
System.out.println("Monkey says " + sound);
}
// Implementing the overloaded method
public void makeSound(String sound, int loudness) {
System.out.println("Monkey says " + sound + " at " + loudness + " decibels");
}
}
public class Main {