Q 2) Smith is currently studying Bachelors in Information Technology(IT), He has an assignment to develop a program using the abstract classes, which displays the following statements:
1. I'm a Line.
2. I'm a Circle.
3. I'm a square
He has to create a Draw() method in a program to display the preceding statements. Help Smith to accomplish the task.
Ans 2)
using System;
namespace DrawShapes
{
public abstract class DrawingObject
{
public abstract void Draw();
}
public class Line : DrawingObject
{
public override void Draw()
{
Console.WriteLine("I'm a Line.");
}
}
public class Circle: DrawingObject
{
public override void Draw()
{
Console.WriteLine("I'm a Circle.");
}
}
public class Square : DrawingObject
{
public override void Draw()
{
Console.WriteLine("I'm a Square.");
}
}
public class DrawDemo{
public static int Main(string[] args)
{
DrawingObject[] dObj = new DrawingObject[3];
dObj[0] = new Line();
dObj[1] = new Circle();
dObj[2] = new Square();
foreach(DrawingObject drawObj in dObj)
{
drawObj.Draw();
}
Console.ReadLine();
return 0;
}
}
}
1. I'm a Line.
2. I'm a Circle.
3. I'm a square
He has to create a Draw() method in a program to display the preceding statements. Help Smith to accomplish the task.
Ans 2)
using System;
namespace DrawShapes
{
public abstract class DrawingObject
{
public abstract void Draw();
}
public class Line : DrawingObject
{
public override void Draw()
{
Console.WriteLine("I'm a Line.");
}
}
public class Circle: DrawingObject
{
public override void Draw()
{
Console.WriteLine("I'm a Circle.");
}
}
public class Square : DrawingObject
{
public override void Draw()
{
Console.WriteLine("I'm a Square.");
}
}
public class DrawDemo{
public static int Main(string[] args)
{
DrawingObject[] dObj = new DrawingObject[3];
dObj[0] = new Line();
dObj[1] = new Circle();
dObj[2] = new Square();
foreach(DrawingObject drawObj in dObj)
{
drawObj.Draw();
}
Console.ReadLine();
return 0;
}
}
}
No comments:
Post a Comment