类型转换 之 引用类型

using System;

namespace ConversationTest
{
    class Car
    {
        string strc="轿车";
        public void PrintC()
        {
            Console.WriteLine(strc+"可乘坐多人");
        }
    }
    class Minicar:Car
    {
        string strm="微型轿车";
        public void PrintM()
        {
            Console.WriteLine(strm+"可乘坐两人");
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            Car c = new Minicar();
            c.PrintC();
       //c.strc;  ---无法访问
       //c.PrintM();  ---无法访问
       //c.strm;  ---无法访问
Type t = c.GetType(); Console.WriteLine("c的类型为:"+t.FullName); } } }
输出结果:
轿车可乘坐多人
c的类型为:ConversationTest.Minicar
个人结论:只可以访问父类中的方法

有什么不完善的地方请大家多多指点!!!

posted on 2009-12-31 10:31  anlantan  阅读(128)  评论(0编辑  收藏  举报

导航