csharp-抽象クラスの継承

  using System;
 
  public abstract class Person
  {
    public abstract string getName();
  }
 
  public class Taro : Person
  {
    public override string getName()
    {
      return "クラスTaro";
    }
  }
 
  public class Class1
  {
    public static int Main(string[] args)
    {
      // 次の行はコンパイルエラーになる。
      // Person person = new Person();//抽象クラスのインスタンスは作成できない
      Taro taro = new Taro();
      Console.WriteLine( taro.getName() );
      Person someone = new Taro();
      Console.WriteLine( someone.getName() );
      return 0;
    }
  }
 
最終更新:2009年05月19日 16:02