首页 > 试题广场 >

阅读以下程序,写出输出结果。

[问答题]

阅读以下程序,写出输出结果。

class superClass {
int y;
 
superClass() {
y = 30;
System.out.println("in superClass:y=" + y);
}
 
void doPrint() {
System.out.println("In superClass.doPrint()");
}
}
 
class subClass extends superClass {
int y;
 
subClass() {
super(); 
y = 50;
System.out.println("in subClass:y=" + y);
}
 
void doPrint() {
super.doPrint(); 
System.out.println("in subClass.doPrint()");
System.out.println("super.y=" + super.y + "  sub.y=" + y);
}
}
 
public class inviteSuper {
public static void main(String args[]) {
subClass subSC = new subClass();
subSC.doPrint();
}
}

大体上这样的
发表于 2017-08-25 19:47:08 回复(0)
in superClass:y=30
in subClass:y=50
In superClass.doPrint()
in subClass.doPrint()
super.y=30  sub.y=50

发表于 2017-05-17 16:17:53 回复(1)