zoukankan      html  css  js  c++  java
  • 子类与父类的小关系:盒子套盒子

    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. }  
  • 相关阅读:
    fork子进程
    多输入使用多线程
    多输入select
    多输入之轮询
    开启telnet
    slickedit编译调试linux应用程序
    电子书框架
    通用Makefile
    STDIN_FILENO和stdin
    libiconv交叉编译提示arm-none-linux-gnueabi-gcc
  • 原文地址:https://www.cnblogs.com/leeolevis/p/1486079.html
Copyright © 2011-2022 走看看