I'm having a few issues while trying use Inheritance. I create a class named vehicle with some properties, and the another one named car which inherits the properties from vehicle, them when I run the code below, the C# compiler returns the following error:
Program.cs (38,13): error CS0246: The namespace name or type 'car' could not be found. Need a policy using or an assembly reference?
Here's the code:
using System;
class vehicle
{
public int MaxSpeed;
public bool turnOn;
public int wheels;
public void car_on()
{
turnOn = true;
}
public void car_off()
{
turnOn = false;
}
class car : vehicle
{
public string name;
public string color;
public car(string name, string color)
{
this.name = name;
this.color = color;
MaxSpeed = 220;
wheels = 4;
turnOn();
}
}
}
namespace Aula_28_herança
{
class Program
{
static void Main(string[] args)
{
car c1= new car("ferrari","red");
Console.WriteLine("Nome................:{0}", c1.name);
Console.WriteLine("Cor.................:{0}", c1.color;
Console.WriteLine("Velociade Máxima....:{0}", c1.MaxSpeed);
Console.WriteLine("Quantiadade de Rodas:{0}", c1.wheels);
Console.WriteLine("Status..............:{0}", c1.turnOn);
}
}
}
caris nested insidevehicle. That is not useful and not recommended. Put them in separate files in the same folder.