zoukankan      html  css  js  c++  java
  • 关于继承的一个小程序

    using System;
    using System.Collections.Generic;
    using System.Text;

    namespace Test
    {
        
    class Program
        
    {
            
    static void Main(string[] args)
            
    {
                B b 
    = new B();
                b.print();
                C c 
    = new C();
                c.print();
                Console.ReadKey();
            }

        }

        
    class A
        
    {
            
    public int a = 3;
        }

        
    class B : A
        
    {
            
    public new int a = 4;
            
    public virtual void print()
            
    {
                Console.WriteLine(
    base.a);
            }

        }

        
    class C : B
        
    {
            
    public override  void print()
            
    {
                Console.WriteLine(
    base.a);
            }

        }

    }
    会输出
    3
    4

    而如果把class C中的print函数整个删除,会输出
    3
    3
  • 相关阅读:
    测试PHP-FPM的工作流中的疑惑点
    摘要
    Centrifugo简单试用
    react-redux的基本用法
    PHP中使用ElasticSearch(二)
    PHP中使用ElasticSearch(一)
    Vue中的状态管理器
    Laravel数据库迁移
    快速搭建一个vue开发环境
    使用cURL尝试ElasticSearch
  • 原文地址:https://www.cnblogs.com/zxsoft/p/872109.html
Copyright © 2011-2022 走看看