明天要考试了,有一道关于java的编程题想请大家帮帮忙啊 ,急!谢谢了

2024-11-07 22:48:57
推荐回答(2个)
回答1:

package MainPackage;

class ParentClass {
String s = "this is ParentClass!";
public ParentClass(){
System.out.println(s);
}
}
class SubClass extends ParentClass{

public SubClass(){
super.s = "this is SubClass!";
System.out.println(s);
}
}
import MainPackage.ParentClass;

public class DemoPackage {

public static void main(String[] args) {
SubClass sub = new SubClass();

}

}

回答2:

我总结一下,一楼正解。