0

Help inheritance c#

Inheritance The program you are given takes the brand and model of the car as input, and defines a Vehicle class with model property and ShowModel() method. Complete the Car class to inherit the Vehicle class, and add the Model property and ShowModel() method so that the given method call of the car object works correctly (see sample output). Sample Input BMW 5 Series Sample Output Brand: BMW Model: 5 Series I tried using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace sololearn_Inheritance { class Program { static void Main(string[] args) { string brandName = Console.ReadLine(); string modelName = Console.ReadLine(); Car car = new Car(); car.Brand = brandName; car.Model = modelName; car.ShowBrand(); car.ShowModel(); } } class Vehicle { public string Brand { get; set; } public void ShowBrand() { Console.WriteLine("Brand: " + Brand); } } //complete the Car class class Car { public string Model { get; set; } public string Brand { get; set; } public void ShowModel() { Console.WriteLine("Model: " + Model); } class Vehicle: Car { string Brand; } } }

21st Jan 2021, 12:35 PM
Abdullah Ghanim
Abdullah Ghanim - avatar
4 ответов
+ 6
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { string brandName = Console.ReadLine(); string modelName = Console.ReadLine(); Car car = new Car(); car.Brand = brandName; car.Model = modelName; car.ShowBrand(); car.ShowModel(); } } class Vehicle { public string Brand { get; set; } public void ShowBrand() { Console.WriteLine("Brand: " + Brand); } } //complete the Car class class Car : Vehicle { public string Model { get; set; } public void ShowModel (){ Console.WriteLine ("Model: "+Model); } } }
6th May 2022, 2:24 PM
Deepika. Shetty
Deepika. Shetty - avatar
+ 3
You're doing it wrong! Kindly read about the syntax of derived class in the lesson. https://www.sololearn.com/learn/CSharp/2678/?ref=app Car class has access to all the properties of it's base class Vehicle. So you don't need to re-write public string Brand {get, set;} in the Car class again. https://code.sololearn.com/cw6VPk4ZExWT/?ref=app
21st Jan 2021, 2:33 PM
Minho
Minho - avatar
+ 1
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading; using System.Threading.Tasks; namespace SoloLearn { class Program { static void Main(string[] args) { string brandName = Console.ReadLine(); string modelName = Console.ReadLine(); Car car = new Car(); car.Brand = brandName; car.Model = modelName; car.ShowBrand(); car.ShowModel(); } } class Vehicle { public string Brand { get; set; } public void ShowBrand() { Console.WriteLine("Brand: " + Brand); } } //complete the Car class class Car : Vehicle { public string Model { get; set; } public void ShowModel (){ Console.WriteLine ("Model: "+Model); } } }
17th Apr 2022, 10:04 PM
Asmaa Nasr
0
Help pls
21st Jan 2021, 12:37 PM
Abdullah Ghanim
Abdullah Ghanim - avatar