如图,写出两个Java程序的运行结果,拜托了

如图
2025-03-07 06:57:23
推荐回答(3个)
回答1:

第一个程序:

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();
    }
}

结果:

回答2:

你编译运行下就好了嘛

回答3:

10 ..5
father son hellworld