C# Program to print student details using single inheritance
In this program, You will learn how to print student details using single-level inheritance in C#.
public class Student {
//statement
}
public class College : Student {
//statement
}
Example: How to print student details using single inheritance in C#.
using System;
public class Student
{
public int roll;
public String cname, sname;
public void input()
{
Console.Write("Enter Roll number:");
roll = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter College name:");
cname = Console.ReadLine();
Console.Write("Enter Student name:");
sname = Console.ReadLine();
}
}
public class College : Student
{
public void display()
{
Console.WriteLine("\n==============Student Details ===========");
Console.WriteLine("Roll number is :" + roll);
Console.WriteLine("College name is :" + cname);
Console.WriteLine("Student name is :" + sname);
}
public static void Main(string[] args)
{
College t1 = new College();
t1.input();
t1.display();
}
}
Output:
Enter Roll number:101
Enter College name:Xiith34
Enter Student name:Xiith
==============Student Details ===========
Roll number is :101
College name is :Xiith34
Student name is :Xiith