欢迎来到.net学习网

欢迎联系站长一起更新本网站!QQ:879621940

您当前所在位置:首页 » C# » 正文

热门阅读

C#中unknown的实现

创建时间:2011年06月21日 08:15  阅读次数:(4934)
分享到:

using System;
namespace dirtysalt
{
 public class Car//class of car,has attribute of 'weight' and 'speed'
 {
  private int weight;
  private int speed;
  public Car(int Weight,int Speed)
  {
   weight=Weight;
   speed=Speed;
  }
  public void setweight(int Weight)
  {
   weight=Weight;
  }
  public void setspeed(int Speed)
  {
   speed=Speed;
  }
  public int getspeed()
  {
   return speed;
  }
  public int getweight()
  {
   return weight;
  }
 };


 public class Sportcar:Car//inherit class of Car,has  attributes of 'weight','speed','color'
 {
  private string color;
  public  Sportcar(int Weight,int Speed,string Color):base(Weight,Speed)
  {
   setweight(Weight);
   setspeed(Speed);
   color=Color;
  }
  public void setcolor(string Color)
  {
   color=Color;
  }
  public string getcolor()
  {
   return color;
  }
  public static void Main()
  {
   Car car=new Car(100,100);
   Sportcar sportcar=new Sportcar(100,200,"blcak");//here has a problem
   Console.WriteLine("car's weight is "+car.getweight());
   Console.WriteLine("car's speed is "+car.getspeed());
   Console.WriteLine("sportcar's weight is "+sportcar.getweight());
   Console.WriteLine("sportcar's speed is "+sportcar.getspeed());
   Console.WriteLine("sportcar's speed is "+sportcar.getcolor());
  }
 }

来源:
说明:所有来源为 .net学习网的文章均为原创,如有转载,请在转载处标注本页地址,谢谢!
【编辑:Wyf

打赏

取消

感谢您的支持,我会做的更好!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

最新评论

共有评论0条
  • 暂无任何评论,请留下您对本文章的看法,共同参入讨论!
发表评论:
留言人:
内  容:
请输入问题 55+53=? 的结果(结果是:108)
结  果: