How to Use Method OverRidding in C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MethodOverRidding
{
abstract class Shapes
{
abstract public int Area();
}
class Square : Shapes
{
int side = 0;
public Square(int n)
{
side = n;
}
public override int Area()
{
return side * side;
}
static void Main()
{
Square sq = new Square(12);
Console.WriteLine("Area of the square = {0}", sq.Area());
Console.Read();
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace MethodOverRidding
{
abstract class Shapes
{
abstract public int Area();
}
class Square : Shapes
{
int side = 0;
public Square(int n)
{
side = n;
}
public override int Area()
{
return side * side;
}
static void Main()
{
Square sq = new Square(12);
Console.WriteLine("Area of the square = {0}", sq.Area());
Console.Read();
}
}
}
0 comments:
Post a Comment