using System;
public abstract class Astrodroid
{
public virtual string GetSound()
{
return "Beep beep";
}
public void MakeSound()
{
//this method should print the returned value of above function
}
}
在MakeSound方法中,我必须打印GetSound方法返回的值。
答案 0 :(得分:3)
您可以从MakeSound调用GetSound()。这是一个实现。
class Program
{
public abstract class Astrodroid
{
public virtual string GetSound()
{
return "Beep beep";
}
public void MakeSound()
{
Console.WriteLine(this.GetSound());
Console.ReadLine();
}
}
public class MyClass:Astrodroid
{
}
static void Main(string[] args)
{
MyClass myClass = new MyClass();
myClass.MakeSound();
}
}