Vegetarianboy30

ml inh in C#

Jan 20th, 2021
630
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2.  * C# Program to Illustrate Multilevel Inheritance with Virtual Methods
  3.  */
  4. using System;
  5. public class Person
  6. {
  7.     protected string RNO = "44";
  8.     protected string name = "Ram";
  9.     public virtual void GetInfo()
  10.     {
  11.         Console.WriteLine("Name: {0}", name);
  12.         Console.WriteLine("RNO: {0}", RNO);
  13.         Console.WriteLine();
  14.     }
  15. }
  16. class Student : Person
  17. {
  18.     public string id = "ABC";
  19.     public override void GetInfo()
  20.     {
  21.         base.GetInfo();
  22.         Console.WriteLine("Student ID: {0}", id);
  23.     }
  24. }
  25. class Stud : Student
  26. {
  27.     private string StudentAddress = "USA";
  28.     public void GetInfo()
  29.     {
  30.         base.GetInfo();
  31.         Console.WriteLine("Student Address: {0}", StudentAddress);
  32.     }
  33. }
  34. class TestClass
  35. {
  36.     public static void Main()
  37.     {
  38.         Student E = new Student();
  39.         E.GetInfo();
  40.         Stud Stud = new Stud();
  41.         Stud.GetInfo();
  42.         Console.ReadLine();
  43.     }
  44. }
RAW Paste Data