public class AWhat do you think the result will be? Don't forget this is a Interview question, that means you have to answer no more than few minutes.
{
void PrintA()
{
Console.WriteLine("Print A");
}
class B : Program
{
new void PrintA()
{
Console.WriteLine("Print B");
}
}
public static void Main()
{
A Atemp = new A();
B Btemp = new B();
Atemp.PrintA();
Btemp.PrintA();
}
}
The answer is:
Print AWhy not and how to get the following result?
Print A
Print A
Print B
The key point is the inner/nested class. We have to declare it is a public class so it's visible to everyone.
No comments:
Post a Comment