标题:C#不是只允许单继承的,怎么可以可以这样继承的,搞不明白
取消只看楼主
新手2012
Rank: 2
等 级:论坛游民
帖 子:4
专家分:13
注 册:2012-10-2
 问题点数:0 回复次数:1 
C#不是只允许单继承的,怎么可以可以这样继承的,搞不明白
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Person
{
    class Program
    {   
       public static void Main(String[] args)
        {
           Chinese c1 = new Chinese();
           c1.name = "Tom";
           c1.height = 170;
           c1.weight = 55;
           c1.speak("Tom",170,55);
           c1.kongfu();
           Korean k1 = new Korean();
           k1.zhengrong();
           Console.ReadKey();
        }
    }
    class Person
    {
       public string name;
       public int height;
       public int weight;
       public void speak(string name,int height,int weight)
       {
           Console.WriteLine("Hello,my name is {0},my height is {1}cm,weight is {2}kg.",name,height,weight);
       }
    }
    class Chinese : Person
    {
        public void kongfu()
        {
            Console.WriteLine("我打,中国人不是东亚病夫!");
        }
    }
    class Korean : Person
    {
        public void zhengrong()
        {
            Console.WriteLine("来,让我来帮你整容!");
        }
    }
}
//求大家帮忙解答下,我对继承真的不怎么明白。
搜索更多相关主题的帖子: public Korean Chinese 继承 
2012-10-03 23:11
新手2012
Rank: 2
等 级:论坛游民
帖 子:4
专家分:13
注 册:2012-10-2
得分:0 
回复 5楼 lybh24
嗯,现在理解了,自学的时候很容易自己理解错,有时听别人说才恍然大悟!
2012-10-04 19:43



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-382501-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018861 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved