1. class Program   
  2. {   
  3.     static void Main(string[] args)   
  4.     {   
  5.         InBox son = new InBox();   
  6.         son.m1();   
  7.         son.m2();   
  8.         Console.WriteLine("转换成父类");   
  9.         Box box = (Box)son;   
  10.         box.m1();     //从这儿就能看出,只有父类的方法,而没有子类的方法了?所以像不像是父类就是子类里的一个盒子?   
  11.     }   
  12. }   
  13.   
  14.   
  15. class Box   
  16. {   
  17.     public void m1()   
  18.     {   
  19.         Console.WriteLine("我是父类的方法");   
  20.         Console.ReadLine();   
  21.     }   
  22. }   
  23.   
  24. class InBox : Box   
  25. {   
  26.     public void m2()   
  27.     {   
  28.         Console.WriteLine("我是子类的方法");   
  29.         Console.ReadLine();   
  30.     }   
  31. }  

相关文章:

  • 2021-11-04
  • 2021-06-03
  • 2021-11-29
  • 2021-09-22
  • 2021-06-03
  • 2021-08-24
  • 2022-12-23
  • 2021-07-03
猜你喜欢
  • 2022-12-23
  • 2021-05-03
  • 2021-10-18
  • 2021-12-10
  • 2022-12-23
  • 2021-11-05
  • 2022-02-10
相关资源
相似解决方案