Complete the code to declare an interface named IAnimal.
public interface [1] {
void Speak();
}The interface name should start with 'I' by convention, so IAnimal is correct.
Complete the code to make the Dog class implement the IAnimal interface.
public class Dog : [1] { public void Speak() { Console.WriteLine("Woof!"); } }
The class Dog must implement the interface IAnimal to fulfill the contract.
Fix the error in the code by completing the interface method declaration.
public interface IAnimal {
[1] Speak();
}Interface methods do not have access modifiers and must specify the return type. Here, void means the method returns nothing.
Fill both blanks to create a dictionary that maps animal names to their sounds using an interface and class.
Dictionary<string, string> animalSounds = new Dictionary<string, string> {
{"Dog", [1],
{"Cat", [2]
};The dog sound is "Woof" and the cat sound is "Meow". These strings represent the sounds animals make.
Fill all three blanks to implement the IAnimal interface in the Cat class with a Speak method.
public class [1] : [2] { public [3] Speak() { Console.WriteLine("Meow"); } }
The class name is Cat, it implements the interface IAnimal, and the Speak method returns void.