本帖最后由 辉Se天空 于 2014-12-28 18:18 编辑
- class Car{
- private String color;
- private String type;
- Car(String color)
- {
- this.color = color;
- System.out.println("color:"+this.color+" type:"+this.type);
- }
- Car(String type)
- {
- this.type = type;
- System.out.println("color:"+this.color+" type:"+this.type);
- }
- Car(String color,String type)
- {
- this.color = color;
- this.type = type;
- System.out.println("color:"+this.color+" type:"+this.type);
- }
- }
复制代码
Car(String color)、Car(String type)的两个构造函数同时存在是错误的,但是我想实现color和type分别赋值,请教大家怎么实现? |