第一个程序:
public class Test {
static int x = 5;
public static void methodA() {
x = x + 5;
System.out.println("x in methodA() = " + x);
}
public static void main(String[] args) {
int x = 5;
methodA();
System.out.println("x in main() = " + x);
}
}
测试结果:
第二个程序:
class Father {
public Father() {
System.out.println("Father");
}
public void sayHello() {
System.out.println("Hello World");
}
}
class Son extends Father {
public Son() {
System.out.println("Son");
}
}
public class Test {
public static void main(String[] args) {
Son son = new Son();
son.sayHello();
}
}
结果:
你编译运行下就好了嘛
10 ..5
father son hellworld