An abstract class may have an abstract property, which should be implemented in the derived class. - CSharp Custom Type

CSharp examples for Custom Type:abstract

Description

An abstract class may have an abstract property, which should be implemented in the derived class.

Demo Code

using System;//from   w  ww .  j  a va2s  .  c o m
public abstract class Person {
   public abstract string Name {
      get;
      set;
   }
   public abstract int Age {
      get;
      set;
   }
}
class Student : Person {
   private string code = "N.A";
   private string name = "N.A";
   private int age = 0;
   // Declare a Code property of type string:
   public string Code {
      get {
         return code;
      }
      set {
         code = value;
      }
   }
   // Declare a Name property of type string:
   public override string Name {
      get {
         return name;
      }
      set {
         name = value;
      }
   }
   // Declare a Age property of type int:
   public override int Age {
      get {
         return age;
      }
      set {
         age = value;
      }
   }
   public override string ToString() {
      return "Code = " + Code +", Name = " + Name + ", Age = " + Age;
   }
}
class ExampleDemo {
   public static void Main() {
      Student s = new Student();
      s.Code = "001";
      s.Name = "Pink";
      s.Age = 9;
      Console.WriteLine("Student Info:- {0}", s);
      s.Age += 1;
      Console.WriteLine("Student Info:- {0}", s);
   }
}

Result


Related Tutorials