62,623
社区成员
发帖
与我相关
我的任务
分享
public Sales(String name,double price,int num,double discount)
{
//因为继承了produce,所以用super(name,price)显现的调用父类的构造函数,
//题外话,如果父类和子类同样有一个use的函数,而在子类中可能用super.use()来访问父类中的use函数
super(name,price);
//为什么在自己类中还有用this呢,感觉怪怪的是吧,
// 答案是因为你的参数 Sales(String name,double price,int num,double discount)
//看到括号里的int num,double discount的参数了吧,它和类中的定义的public int num; public double discount;的一样,为了以似区别,所以必须加上this
//不然,在你的构造函数里面,只不过是对参数的赋值
this.num=num;
this.discount=discount;
}
class TestThis {
private TestThis this = new TestThis();
public TestThis() {
}
}