天涯1990 / c#小程序 / unknown

分享

   

unknown

2010-11-12  天涯1990
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());
  }
 }
}
 

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多
    喜欢该文的人也喜欢 更多

    ×
    ×

    ¥.00

    微信或支付宝扫码支付:

    开通即同意《个图VIP服务协议》

    全部>>