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.
|
|
|
|
# 考题
|
|
|
|
|
|
|
|
|
|
不运行代码,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();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
```
|