Example 1: C# program for Abstract class
Program.cs
abstract class Arithmetic { public int add(int a, int b) { int c = a + b; return c; } public void display(int c) { Console.Write("Addition " + c); } } class Program : Arithmetic { public static void Main(String[] args) { Program p = new Program(); int addition = p.add(10, 10); p.display(addition); } }
Output
kodingwindow@kw:~/csharp$ dotnet run Addition 20 kodingwindow@kw:~/csharp$
Example 2: C# program for Abstract class
Program.cs
WhiteBank wb = new WhiteBank(); GreenBank gb = new GreenBank(); wb.Bonus(); gb.Bonus(); abstract class Bank { public abstract void Bonus(); } class WhiteBank : Bank { public override void Bonus() { Console.WriteLine("Festival Bonus: WhiteBank 1500"); } } class GreenBank : Bank { public override void Bonus() { Console.Write("Festival Bonus: GreenBank 500"); } }
Output
kodingwindow@kw:~/csharp$ dotnet run Festival Bonus: WhiteBank 1500 Festival Bonus: GreenBank 500 kodingwindow@kw:~/csharp$
Comments and Reactions
What Next?
C# program to demonstrate the use of an interface
How to achieve Multiple Inheritance in C# using interfacesC# NamespacesAdvertisement