代码如下,我想问问定义第二个构造方法时为什么第一句必须要写super(name); 还有假如我在main方法中写OverrideTest str=new OverrideTest2("你好");是什么含义。为什么前面的类型是Override而new后面接的是Override2呢?
_package overrideTest;
abstract class OverrideTest {
private String name;
public OverrideTest(String name) {
yes(name);
}
public void yes(String name) { //定义一个判断方法
if(name=="你好")
{
this.name="你好";
System.out.println(this.name);
}
}
}
class OverrideTest2 extends OverrideTest {
public String name;
public OverrideTest2(String name) {
super(name);
if(name=="你好") {
this.name="不好";
System.out.println(this.name);
}
}
}
_