C# Program to add three numbers using single-level inheritance


In this program, You will learn how to add three numbers using single-level inheritance in C#.


public class A { 
  //statement
}

public class B : A { 
  //statement
}

Example: How to add three numbers using single-level inheritance in C#.

using System;
public class First
{
	public int a, b, c, sum;

	public void input()
	{
		Console.Write("Enter three numbers:");
		a = Convert.ToInt32(Console.ReadLine());
		b = Convert.ToInt32(Console.ReadLine());
		c = Convert.ToInt32(Console.ReadLine());
	}
}
public class Second : First
{
	public void add()
	{
		sum = a + b + c;
	}
	public void display()
	{
		Console.WriteLine("Sum is:" + sum);
	}

	public static void Main(string[] args)
	{
		Second t1 = new Second();
		t1.input();
		t1.add();
		t1.display();
	}
}

Output:

Enter three numbers:10
20
30
Sum is:60