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喲
所有跟帖:
• 回複:有人能答出這到.NET的題嗎?非常TRICKY喲 -st.paul- ♂ (352 bytes) () 09/13/2009 postreply 13:42:48
• 這位朋友的確很牛 -牛牛哥- ♀ (61 bytes) () 09/14/2009 postreply 08:15:30
• 實際上這個不是完全可以的 -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- ♂ (206 bytes) () 09/14/2009 postreply 13:17:12
• 不可以加NEW啊 -牛牛哥- ♀ (77 bytes) () 09/14/2009 postreply 19:13:44
• 回複:要略改動才可以 (加new keyword) -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- ♀ (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- ♀ (124 bytes) () 09/16/2009 postreply 06:30:15
• 你好像不懂的什麽是Derived,什麽是Base,也不懂得題意 -st.paul- ♂ (118 bytes) () 09/16/2009 postreply 08:53:12