面向对象编程 java试题。 如图所示

面向对象编程 java试题。
如图所示

第1个回答  2015-12-21
这种题太简单了吧
public class Bicycle {

private String brand = "未知品牌";
private int price = 0;
private String productData = "尚无日期";

public Bicycle() {}

public Bicycle(String brand, int price, String productData) {
this.brand = brand;
this.price = price;
this.productData = productData;
}

public void showInfo() {
System.out.println("brand: "+brand);
System.out.println("price: "+price);
System.out.println("productData: "+productData);
}

public void setBrand(String brand) {
this.brand = brand;
}
public void setPrice(int price) {
this.price = price;
}

public void setProductData(String productData) {
this.productData = productData;
}

}
public class BicycleDemo {

public static void main(String[] args) {
Bicycle bicycle1 = new Bicycle();
Bicycle bicycle2 = new Bicycle("凤凰",100,"2013/06/19");
bicycle1.showInfo();
bicycle2.showInfo();
}

}
第2个回答  2015-12-21
public class BicycleDemo {


public static void main(String[] args) {
Bicycle b1 = new Bicycle("吉安待",3600,"2015/12/29");
Bicycle b2 = new Bicycle("宝马",70000,"2010/10/10");
b1.showInfo();
b2.showInfo();

}

}

class Bicycle{
private String brand;
private int price;
private String productDate;

public Bicycle(){

}
public Bicycle(String brand, int price, String productDate){
this.brand = brand;
this.price = price;
this.productDate = productDate;
}

public void showInfo(){
System.out.println("品牌: "+this.brand+", 价格: "+this.price+", 生产日期: "+this.productDate);
}
}

本回答被网友采纳
第3个回答  2015-12-21
public class Bicycle{
//三个成员变量

private String brand;
private int price;
private String productDate;
//输出信息方法

public void showinfo(){
System.out.println("Brand:"+brand+"price:"+price+"productDate:"+productDate);
}
//无参构造函数

public Bicycle(){

}
//有参构造函数

public Bicycle(String brand, int price,String productDate){

}

}

//采纳后给你最后一题
第4个回答  2015-12-21
哎 ......
相似回答