The purpose is to create Circle and Triangle class by inheriting the Shape Class. Both the inherited classes should override the WhoamI() method of the Shape Class. The code has some bugs. Identify the Bugs and fix them.
public class Shape
{
private void WhoamI()
{
Console.WriteLine("I m Shape");
}
}
class Triangle : public Shape
{
public virtual void WhoamI()
{
Console.WriteLine("I m Triangle");
}
}
public class Circle : public Shape
{
void WhoamI()
{
Console.WriteLine("I m Circle");
}
}
class Program
{
static void Main(string[] args)
{
Shape s; s = new Triangle();
s.WhoamI();
s = new Circle();
s.WhoamI();
Console.ReadKey();
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
namespace C_SHARP
{
public class Shape
{
public virtual void WhoamI()
{
Console.WriteLine("I m Shape");
}
}
class Triangle : Shape
{
public override void WhoamI()
{
Console.WriteLine("I m Triangle");
}
}
public class Circle : Shape
{
public override void WhoamI()
{
Console.WriteLine("I m Circle");
}
}
class Program
{
static void Main(string[] args)
{
Shape s;
s = new Triangle();
s.WhoamI();
s = new Circle();
s.WhoamI();
Console.ReadKey();
}
}
}
Comments
Leave a comment