Users Online

· Guests Online: 64

· Members Online: 0

· Total Members: 188
· Newest Member: meenachowdary055

Forum Threads

Newest Threads
No Threads created
Hottest Threads
No Threads created

Latest Articles

C# Program to Demonstrate the Overriding

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.

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

 

Comments

No Comments have been Posted.

Post Comment

Please Login to Post a Comment.

Ratings

Rating is available to Members only.

Please login or register to vote.

No Ratings have been Posted.
Render time: 0.75 seconds
10,844,574 unique visits