- class Oneclass
- {
- public string str1 = "this is Oneclass";
- public void print1( string value)
- {
- Console.WriteLine(value);
- }
- }
- class Otherclass : Oneclass
- {
- public string str2 = "this is Otherclass";
- public void print2(string value)
- {
- Console.WriteLine(value);
- }
- }
- class Program
- {
- static void Main(string[] args)
- {
- Otherclass c = new Otherclass();
- c.print2(c.str1);
- Console.ReadKey();
- }
- }
复制代码 我不明白为什么基类能有派生类的方法?求解 |