public static void Main()
Person[] people = new Person[4] {
new Student("Tej", 17, 111372),
new Teacher("Anna Sargsyan", 25, "Computer Science", 6)};
foreach(Person person in people) {
public abstract class Person {
public string Name = "Default";
public abstract void DisplayDetails();
public class Student: Person {
public Student(string name, int age, int id) {
public override void DisplayDetails() {
Console.WriteLine($"The student's name is {Name} and their age is {Age}; their id is {StudentId}");
public class Teacher: Person {
public int NumberPeriods;
public Teacher(string name, int age, string subject, int numberPeriods) {
NumberPeriods = numberPeriods;
public override void DisplayDetails() {
Console.WriteLine($"The teacher's name is {Name} and their age is {Age}; they teach {Subject} for {NumberPeriods} periods.");