T
Tony Johansson
Hi!
If I don't override method ToString in class Car will
ToString in the dynamic class SportCar be called in main because method
ToString is defined as virtual.
I can understand that.
But if I override this ToString method in class Car will class Car be used
when I use car:ToString in main.
I just wonder when I override ToString in class Car why is then class car
used instead of Sportcar that
was used when no override of ToString existed ??
Normally I know how it works if I only have user defined methods but here we
have this ToString which
cause me to be a litle bit uncertain.
public static void Main()
{
Car car = new SportCar();
Console.WriteLine(car.ToString());
}
public class Car
{
public string ToString()
{
return "Car";
}
}
public class SportCar : Car
{}
//Tony
If I don't override method ToString in class Car will
ToString in the dynamic class SportCar be called in main because method
ToString is defined as virtual.
I can understand that.
But if I override this ToString method in class Car will class Car be used
when I use car:ToString in main.
I just wonder when I override ToString in class Car why is then class car
used instead of Sportcar that
was used when no override of ToString existed ??
Normally I know how it works if I only have user defined methods but here we
have this ToString which
cause me to be a litle bit uncertain.
public static void Main()
{
Car car = new SportCar();
Console.WriteLine(car.ToString());
}
public class Car
{
public string ToString()
{
return "Car";
}
}
public class SportCar : Car
{}
//Tony