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

Xiith is created for educational, experimental, and schooling purpose. Examples on Xiith are made easier to make a better or basic understanding. Tutorials, testimonials, and examples are continuously checked to avoid delusion, but we cannot take complete responsibility of all programs on Xiith. When you are operating this site, you have to agree to read and accept our terms of use, cookie and privacy policy.Copyright © 2020 by Xiith. All Rights Reserved. About us.