有人能答出这到.NET的题吗?非常TRICKY哟

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. 有人愿意试试吗?
*/

}
}

所有跟帖: 

回复:有人能答出这到.NET的题吗?非常TRICKY哟 -st.paul- 给 st.paul 发送悄悄话 (352 bytes) () 09/13/2009 postreply 13:42:48

这位朋友的确很牛 -牛牛哥- 给 牛牛哥 发送悄悄话 牛牛哥 的博客首页 (61 bytes) () 09/14/2009 postreply 08:15:30

实际上这个不是完全可以的 -st.paul- 给 st.paul 发送悄悄话 (850 bytes) () 09/14/2009 postreply 09:35:38

实际上是要HACK V-TABLE,我也没搞出来,也没资料找 -牛牛哥- 给 牛牛哥 发送悄悄话 牛牛哥 的博客首页 (0 bytes) () 09/14/2009 postreply 19:15:51

要略改动才可以 (加new keyword) -st.paul- 给 st.paul 发送悄悄话 (206 bytes) () 09/14/2009 postreply 13:17:12

不可以加NEW啊 -牛牛哥- 给 牛牛哥 发送悄悄话 牛牛哥 的博客首页 (77 bytes) () 09/14/2009 postreply 19:13:44

回复:要略改动才可以 (加new keyword) -Largo- 给 Largo 发送悄悄话 (185 bytes) () 09/14/2009 postreply 19:53:32

不是在CLASS LEVEL CALL BASE.EAT(), 要求在OBJECT上 -牛牛哥- 给 牛牛哥 发送悄悄话 牛牛哥 的博客首页 (143 bytes) () 09/14/2009 postreply 20:07:08

try this, 包你满意 -me123456- 给 me123456 发送悄悄话 (128 bytes) () 09/15/2009 postreply 14:16:12

这个结果是对的,但是不是用的wolf -牛牛哥- 给 牛牛哥 发送悄悄话 牛牛哥 的博客首页 (66 bytes) () 09/15/2009 postreply 18:50:14

It is still from the wolf. If you don't want wolf0, try this. (( -me123456- 给 me123456 发送悄悄话 (124 bytes) () 09/16/2009 postreply 06:30:15

你好像不懂的什么是Derived,什么是Base,也不懂得题意 -st.paul- 给 st.paul 发送悄悄话 (118 bytes) () 09/16/2009 postreply 08:53:12

请您先登陆,再发跟帖!