牛牛哥2009-09-13 18:42:40
public class MyClass
{
public class Animal
{
public virtual void Eat()
{
Console.WriteLine("I eat like a generic Animal.");
}
}

public class Wolf : Animal
{
public override void Eat()
{
Console.WriteLine("I eat like a wolf!");
}
}

public static void Main(string[] args)
{

Wolf wolf = new Wolf();

/*
如何能用OBJECT wolf 调用其BASECLASS Eat() PRINTOUT “I eat like a generic Animal”,HINT:由于Eat() method 是OVERRIDE的POLYMORPHISIM,CASTING BACK TO BASECALSS won't work. 有人愿意试试吗?
*/

}
}
st.paul2009-09-13 21:42:48
回复:有人能答出这到.NET的题吗?非常TRICKY哟
牛牛哥2009-09-14 16:15:30
这位朋友的确很牛
st.paul2009-09-14 17:35:38
实际上这个不是完全可以的
st.paul2009-09-14 21:17:12
要略改动才可以 (加new keyword)
牛牛哥2009-09-15 03:13:44
不可以加NEW啊
牛牛哥2009-09-15 03:15:51
实际上是要HACK V-TABLE,我也没搞出来,也没资料找
Largo2009-09-15 03:53:32
回复:要略改动才可以 (加new keyword)
牛牛哥2009-09-15 04:07:08
不是在CLASS LEVEL CALL BASE.EAT(), 要求在OBJECT上
me1234562009-09-15 22:16:12
try this, 包你满意
牛牛哥2009-09-16 02:50:14
这个结果是对的,但是不是用的wolf
me1234562009-09-16 14:30:15
It is still from the wolf. If you don't want wolf0, try this. ((
st.paul2009-09-16 16:53:12
你好像不懂的什么是Derived,什么是Base,也不懂得题意