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

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值