0% found this document useful (0 votes)
1 views3 pages

Spring 2025_CS411_1_BC220419189

The document contains a solution for CS411 Assignment #01 for Spring 2025 by student BC220419189. It includes C# code that defines a base class 'Shape' and three derived classes: 'Circle', 'Square', and 'Triangle', each overriding the 'Display' method. The main program creates an array of shapes and calls the 'Display' method for each shape, demonstrating polymorphism in action.

Uploaded by

umehammad2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views3 pages

Spring 2025_CS411_1_BC220419189

The document contains a solution for CS411 Assignment #01 for Spring 2025 by student BC220419189. It includes C# code that defines a base class 'Shape' and three derived classes: 'Circle', 'Square', and 'Triangle', each overriding the 'Display' method. The main program creates an array of shapes and calls the 'Display' method for each shape, demonstrating polymorphism in action.

Uploaded by

umehammad2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

CS411 Assignment # 01 Solution Spring 2025

BC220419189
UM E HAMMAD

Output Screenshot:

C# Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CS411_1_S25
{
class Shape
{
public virtual void Display()
{
Console.WriteLine("I am a generic shape.");
}
}

class Circle : Shape


{
public override void Display()
{
Console.WriteLine("I am a circle shape.");
}
}

class Square : Shape


{
public override void Display()
{
Console.WriteLine("I am a square shape.");
}
}

class Triangle : Shape


{
public override void Display()
{
Console.WriteLine("I am a triangle shape.");
}
}
internal class Program
{
static void Main(string[] args)
{
Console.WriteLine("My Student ID is BC220419189\n");

Shape[] shapes = new Shape[4];

shapes[0] = new Shape();


shapes[1] = new Circle();
shapes[2] = new Square();
shapes[3] = new Triangle();

foreach (Shape shape in shapes)


{
shape.Display();
}

Console.ReadLine();
}
}
}

You might also like