I have a question about the casting from Base to get Derive Class method. Here is my code:
class Vehicles
{
public void SpecificRequiredTask()
{
Console.WriteLine("Base method");
}
}
class Cars : Vehicles
{
public new void SpecificRequiredTask()
{
Console.WriteLine("Derive method");
}
}
class Program
{
Vehicles car = new Cars();
//I want to call the derive method, not base method, so that I do the
//casting
((Cars)car).SpecificRequiredTask();
}
The problem is my professor said that "This is not required because you already have an object of type Cars." But I know that without the casting (Cars), the program will still call the method from Base class.
Please help me to correct my understanding if it's incorrect. Thank you