class DianHua
{
private String name;
private int price;
void Phone(){};
void Phone(String name,int price)
{
this.name = name;
this.price = price;
}
public void setName(String name)
{
this.name = name;
}
public String getName()
{
return name;
}
public void setPrice(int price)
{
this.price = price;
}
public int getPrice()
{
return price;
}
public void call()
{
System.out.println("打电话");
}
public void sendMessage()
{
System.out.println("发信息");
}
public void playGame()
{
System.out.println("玩游戏");
}
}
class Phone
{
public static void main(String[] atgs)
{
DianHua d = new DianHua();
d.setName("华为");
d.setPrice(8888);
System.out.println(d.getName()+"...."+d.getPrice());
DianHua a = new DianHua("中兴",65);
//System.out.println(name+"*****"+price);
}
}
绿色的为空参构造及其初始化
红色的为有参构造,但是编译的时候提示
---------- javac ----------
Phone.java:48: 错误: 无法将类 DianHua中的构造器 DianHua应用到给定类型;
DianHua a = new DianHua("中兴",65);
^
需要: 没有参数
找到: String,int
原因: 实际参数列表和形式参数列表长度不同
1 个错误
-----------------------------------------------------------------------------------------
为什么 ?本人菜鸟 勿喷.
|
-
捕获.JPG
(8.36 KB, 下载次数: 19)
编译出错
|