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();
}
}
我总结一下,一楼正解。