Derived Classes Practice
A class called Vehicle
is given. Apart from that there are two other classes called Car
and Plane
.
There is currently an error in the code. To fix the error you need to make the Car
and Plane
inherit from Vehicle
.
Edit the code such that Car
and Plane
become the child classes of Vehicle
.
index
99
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
using System;
public class Vehicle
{
public int modelYear;
public float fuel;
}
public class Car
{
public void Drive()
{
Console.WriteLine("The car is now driving.");
}
}
public class Plane
{
public void Fly()
{
Console.WriteLine("The plane is now flying.");
}
}
public class Program
{
public static void Main(string[] args)
{
Car c1 = new Car();
Plane p1 = new Plane();
c1.modelYear = 2024;
p1.fuel = 6000;
Console.WriteLine("Executed Successfully");
}
12345678910111213141516171819202122232425262728293031323334353637using System; public class Vehicle { public int modelYear; public float fuel; } public class Car { public void Drive() { Console.WriteLine("The car is now driving."); } } public class Plane { public void Fly() { Console.WriteLine("The plane is now flying."); } } public class Program { public static void Main(string[] args) { Car c1 = new Car(); Plane p1 = new Plane(); c1.modelYear = 2024; p1.fuel = 6000; Console.WriteLine("Executed Successfully"); } }
Var allt tydligt?
Tack för dina kommentarer!
Avsnitt 4. Kapitel 2
Fråga AI
Fråga vad du vill eller prova någon av de föreslagna frågorna för att starta vårt samtal