Was just going through a quiz online for interview prep in C#
. I read this problem:
using System;
// ...
public class Program
{
static void Main(string[] args)
{
Derived d = new Derived();
int i = 10;
d.Func(i);
}
}
public class Base
{
public virtual void Func(int x)
{
Console.WriteLine("Base.Func(int)");
}
}
public class Derived : Base
{
public override void Func(int x)
{
Console.WriteLine("Derived.Func(int)");
}
public void Func(object o)
{
Console.WriteLine("Derived.Func(object)");
}
}
And it says that the output should actually be Derived.Fun(Object)
. Can you help me to understand why it would do this? I thought it would call the Func
command with the integer as the parameter.