C# Program to Demonstrate the Overriding

This is a C# Program to demonstrate the concept of overriding.

Problem Description

This C# Program Demonstrates the concept of Overriding.

Problem Solution

Here the override modifier is required to extend or modify the abstract or virtual implementation of an inherited method, property, indexer, or event.

Program/Source Code

Here is source code of the C# Program to Demonstrate the concept of Overriding. The C# program is successfully compiled and executed with Microsoft Visual Studio. The program output is also shown below.

/*
 * C# Program to Demonstrate the concept of Overriding
 */
using System;
abstract class ShapesClass
{
    abstract public double Area();
}
class Circle : ShapesClass
{
    int radius = 0;
    public Circle(int n)
    {
        radius = n;
    }
    public override double Area()
    {
        return 3.14 * radius * radius;
    }
    static void Main()
    {
        int r;
        Console.WriteLine("Enter the Radius :");
        r = int.Parse(Console.ReadLine());
        Circle c1 = new Circle(r);
        Console.WriteLine("Area of the Circle = {0}", c1.Area());
        Console.ReadLine();
    }
}
Program Explanation

In this C# Program, we are reading the radius of the circle using ‘r’ variable. Perform the operations of Circle() function by passing ‘r’ variable value as an argument. The override modifier is required to extend or modify the abstract or virtual implementation of an inherited method, property, indexer, or event.

advertisement
advertisement
Runtime Test Cases
 
Enter the Radius : 3
Area of the Circle : 28.26

Sanfoundry Global Education & Learning Series – 1000 C# Programs.

If you wish to look at all C# Programming examples, go to 1000 C# Programs.

If you find any mistake above, kindly email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.