Complete the code to declare that the class implements the interface.
public interface IAnimal {
void Speak();
}
public class Dog : [1] {
public void Speak() {
Console.WriteLine("Woof!");
}
}The class Dog implements the interface IAnimal using a colon followed by the interface name.
Complete the code to implement the interface method correctly.
public interface IShape {
double GetArea();
}
public class Square : IShape {
private double side;
public Square(double side) {
this.side = side;
}
public double [1]() {
return side * side;
}
}The method name must exactly match the interface method GetArea to implement it.
Fix the error by completing the code to explicitly implement the interface method.
public interface ILogger {
void Log(string message);
}
public class ConsoleLogger : ILogger {
void [1].Log(string message) {
Console.WriteLine(message);
}
}Explicit interface implementation requires prefixing the method with the interface name ILogger.
Fill both blanks to complete the interface and class implementation with a property.
public interface ICar {
int [1] { get; set; }
}
public class Sedan : ICar {
private int speed;
public int [2] {
get { return speed; }
set { speed = value; }
}
}The property name must be the same in the interface and the class to implement it correctly.
Fill all three blanks to implement multiple interfaces with methods.
public interface IFlyable {
void [1]();
}
public interface ISwimmable {
void [2]();
}
public class Duck : [3] {
public void Fly() {
Console.WriteLine("Flying");
}
public void Swim() {
Console.WriteLine("Swimming");
}
}The class Duck implements both interfaces IFlyable and ISwimmable. The methods must match the interface method names.