110,534
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Text;
using System.Threading;
namespace OOTest
{
public class Father
{
public virtual void TestVoice()
{
Console.WriteLine("Father_TestVoice");
}
public void Test()
{
Console.WriteLine("Father Test");
}
}
public class Son : Father
{
public void SonVoice()
{
Console.WriteLine("Father_TestVoice");
}
public override void TestVoice()
{
Console.WriteLine("Son_TestVoice");
}
public new void Test()
{
Console.WriteLine("Son Test");
}
public static void Main()
{
Father son = new Son();
son.TestVoice();
son.Test();
((Father)son).TestVoice();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace ConsoleApplication24
{
class Program
{
public class Father : Son
{
public int a = 1;
public int b = 2;
public int getb()
{
return b;
}
}
public interface Son
{
int getb();
}
public static void Main()
{
Son f = new Father();
Console.WriteLine(f.getb());
Console.Read();
}
}
}