日期:2014-05-20  浏览次数:20669 次

类构建方法问题
//类构建方法练习
class phone
{
phone(){};
phone(String b,String c,double p)
{
System.out.println(b + "---------" + p);
};
String brand;//品牌
String color;//颜色
double price;//价格
}
class leiTest 
{
public static void main(String[] args) 
{
phone p = new phone();
System.out.println(p);
p = new phone("iphone","red",2999.0);
}
}

main方法的第一行代码phone p = new phone();为什么不能写为phone p = new phone(String b,String c,double p);

------解决方案--------------------
那是要传参数进去啊。第三行就是你要的

p = new phone("iphone","red",2999.0);