C#学习笔记之——类

类的概述

 

类的继承

using System;

namespace Test
{
    class Program
    {
        static void Main(string[] args)
        {
            T1 t1 = new T1();
            Console.WriteLine();
            T4 t4 = new T4();
            Console.WriteLine();
            T5 t5 = new T5();
            Console.WriteLine();
            T6 t6 = new T6();
            t6.P();
            Console.WriteLine();
            T7 t7 = new T7();
            t7.P();
            Console.WriteLine();
        }

    }
    class T
    {
        public T()
        {
            Console.WriteLine("This is T");
        }
        public virtual void P()
        {
            Console.WriteLine("Here is P");
        }
    }
    class T1 : T
    {
        public T1()
        {
            Console.WriteLine("This is T1");
        }

    }

    abstract class T3 : T
    {
        public T3()
        {
            Console.WriteLine("This is T3");
        }

    }

    class T4 : T3
    {
        public T4()
        {
            Console.WriteLine("This is T4");
        }
    }

    interface I
    {
        
    }

    interface I1
    {

    }

    class T5 : T, I, I1
    {
        public T5()
        {
            Console.WriteLine("This is T5");
        }
    }

    class T6 : T
    {
        public override void P()
        {
            base.P();
        }
    }

    class T7 : T
    {
        
        public override void P()
        {
            Console.WriteLine("Here is new P");
        }
    }
}

结果: 

This is T
This is T1

This is T
This is T3
This is T4

This is T
This is T5

This is T
Here is P

This is T
Here is new P

 

posted @ 2019-06-12 17:29  养鼠的猫  阅读(93)  评论(0编辑  收藏  举报