zoukankan      html  css  js  c++  java
  • C#继承机制

     1 using System;
     2  
     3 public class Parent
     4 {
     5     string parentString;
     6     public Parent()
     7     {
     8         Console.WriteLine("Parent Constructor.");
     9     }
    10     public Parent(string myString)
    11     {
    12         parentString = myString;
    13         Console.WriteLine(parentString);
    14     }
    15     public void print()
    16     {
    17         Console.WriteLine("I'm a Parent Class.");
    18     }
    19 }
    20  
    21 public class Child : Parent
    22 {
    23     public Child() : base("From Derived")
    24     {
    25         Console.WriteLine("Child Constructor.");
    26     }
    27     public new void print()
    28     {
    29         base.print();
    30         Console.WriteLine("I'm a Child Class.");
    31     }
    32     public static void Main()
    33     {
    34         Child child = new Child();
    35         child.print();
    36         ((Parent)child).print();
    37     }
    38 }

    注意new,base。

  • 相关阅读:
    JavaScript闭包
    模块模式——方法
    产品与技术
    读书笔记
    屌丝求职记
    正则表达式regex狂记
    css狂记
    html狂记
    Android狂记忆
    关于调式
  • 原文地址:https://www.cnblogs.com/johnpher/p/2741277.html
Copyright © 2011-2022 走看看