| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1496 人关注过本帖
标题:[推荐]好代码不独享
只看楼主 加入收藏
bingxue
Rank: 1
等 级:新手上路
帖 子:19
专家分:0
注 册:2005-3-23
收藏
 问题点数:0 回复次数:17 
[推荐]好代码不独享

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()); } } } 希望对大家有帮助!!!!!!

ps:没有代码说明

[此贴子已经被幻风幻云于2005-4-4 19:31:16编辑过]

搜索更多相关主题的帖子: 代码 推荐 不独 
2005-04-04 18:38
幻风幻云
Rank: 1
等 级:新手上路
帖 子:762
专家分:0
注 册:2005-1-14
收藏
得分:0 
麻烦楼主以后贴类似帖子的时候,能附加代码说明,辛苦了!

2005-04-04 19:32
nyzfl
Rank: 1
等 级:新手上路
帖 子:278
专家分:0
注 册:2005-3-21
收藏
得分:0 
不知是干什么 的

My-Blog地址:http://fenglin.
2005-04-05 12:08
gaofangtao
Rank: 1
等 级:新手上路
帖 子:128
专家分:0
注 册:2005-4-7
收藏
得分:0 

对楼主的东西少加改造,大家别介意啊! using System; namespace dirtysalt{ public class Car // 声明一个car类,他包括 wight,speed 两个字段 { private int weight; private int speed; //下面这是一个带参数的构造函数 public Car(int Weight,int Speed){ weight=Weight; speed=Speed; } //SET方法 public void setweight(int Weight){ weight=Weight; } public void setspeed(int Speed){ speed=Speed; } //get方法 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; //下面是定义一个继承类,继承于car类。 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()); } } }

[em48][em48]

我相信我的付出
2005-04-07 22:46
shiuly
Rank: 1
等 级:新手上路
帖 子:53
专家分:0
注 册:2005-4-7
收藏
得分:0 
ok了,有了註釋就好看多了嘛
2005-04-07 23:18
梦幻情缘
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:769
专家分:20
注 册:2005-4-4
收藏
得分:0 
好改得不错!
2005-04-08 07:31
yichen
Rank: 1
等 级:新手上路
帖 子:303
专家分:0
注 册:2005-3-9
收藏
得分:0 
楼主 ,写的是不是 继承类啊?
不过加了一些注释就好看多了.

衣带渐宽终不悔, 为伊消得人憔悴。 纸上得来终觉浅, 绝知此事要躬行。
2005-04-08 13:42
提灯寻影
Rank: 1
等 级:新手上路
帖 子:85
专家分:0
注 册:2005-4-7
收藏
得分:0 
看不懂 啊!

2005-04-08 18:27
loveys
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2005-4-8
收藏
得分:0 
就是,加点注释更好。
2005-04-08 22:08
梦幻情缘
Rank: 6Rank: 6
等 级:贵宾
威 望:29
帖 子:769
专家分:20
注 册:2005-4-4
收藏
得分:0 
好多呀!这样就好.
2005-04-09 10:24
快速回复:[推荐]好代码不独享
数据加载中...
 
   



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

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