打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
unknown
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());
  }
 }
}
 
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
面向对象设计(二)——对象间的关系引发的思考
C#中ToDictionary,ToLookup
数据结构与算法:04 C#面向对象设计 II
Kruskal 最小生成树算法
C#中要使一个类支持FOREACH遍历,实现过程怎样?
c 类与c#类的区别
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服