public Person(string i, string n)
public void displayDetails()
Console.WriteLine("ID : {0}", id);
Console.WriteLine("Name : {0}", name);
public class Teacher : Person
public Teacher(string i, string n, double s)
: base(i, n) { salary = s; }
public Teacher(string i, string n)
public double getSalary() { return salary; }
public void setSalary(double s)
if (s > 25000) Console.WriteLine("Salary over the limit!");
public void displayDetails()
Console.WriteLine("== TEACHER DETAILS ==");
Console.WriteLine("Salary : {0:c2}", salary);
public class Student : Person
public Student(string i, string n, int b)
public int getBirthYear(){
return (DateTime.Now.Year - birthYear);
public void displayDetails()
Console.WriteLine("== STUDENT DETAILS ==");
Console.WriteLine("Birth Year: {0}", birthYear);
Console.WriteLine("Age : {0}", this.getAge());
static void Main(string[] args)
Teacher tc1 = new Teacher("T003", "Mam");
Teacher tc2 = new Teacher("T008", "Neena", 3000);
Student st1 = new Student("S007", "Yoy", 2010);
Student st2 = new Student("S009", "Peter", 2012);