Computer Science, asked by andysarfo177, 8 months ago

Given the source code below, provide the missing code in the main method that demonstrates polymorphism with the following guidelines. [30 marks] Create an array object “computer” of the type Computer. The “computer” array object size is 3. Create three different laptop instances and assign each to the array element. Use a “foreach” loop to print the laptop information as displayed in the sample output using the “PrintDetails” method of the Laptop class. Sample output should look like Name : Lenovo Price : $1000 Processor : i3 Ram : 2GB HDD : 500GB Name : Dell Price : $1500 Processor : i5 Ram : 4GB HDD : 1TB Name : Sony Price : $2000 Processor : i9 Ram : 8GB HDD : 1TB using System; namespace ComputerApp { class Program { static void Main(string[] args) { // Provide the solution here } } class Computer { protected string Name { get; set; } protected double Price { get; set; } protected string Processor { get; set; } protected string Ram { get; set; } protected string HHD { get; set; } public virtual void PrintDetails() { } } class Laptop : Computer { public Laptop(string newName, double newPrice, string newProcessor, string newRam, string newHHD) { Name = newName; Price = newPrice; Processor = newProcessor; Ram = newRam; HHD = newHHD; } public override void PrintDetails() { Console.WriteLine("Name : {0}", Name); Console.WriteLine("Price : ${0}", Price); Console.WriteLine("Processor : {0}", Processor); Console.WriteLine("Ram : {0}", Ram); Console.WriteLine("HHD : {0}", HHD); } } }

Answers

Answered by Pikachu07
2

· Polymorphism is often referred to as the third pillar of ... In your source code you can call a method on a base class, and ... The following code provides an example:.

Similar questions