You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

65 lines
1.0 KiB
Markdown

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

# 考题
不运行代码20分钟内给出程序输出结果(两个数字)
## 请写出下面代码的输出
``` csharp
public interface I
{
void Print();
}
public class ClassA : I
{
public int i = 1;
public ClassA()
{
++ i;
}
void I.Print()
{
Console.WriteLine(i);
}
public virtual void Print()
{
Console.WriteLine(++i);
}
}
public class ClassB : ClassA, I
{
int i = -1;
public override void Print()
{
Console.WriteLine(--i);
}
}
public class ClassC : ClassA
{
int i = -1;
public override void Print()
{
Console.WriteLine(--i);
}
}
class Program
{
static void Main(string[] args)
{
I i;
i = new ClassB();
i.Print();
i = new ClassC();
i.Print();
}
}
```