Answer: No

Explanation:

(Look at the code first)

The parent class Father. Java:

public class Father {

    public static String test = "Parent static variable";

    public static void test(a){
        System.out.println("This is the parent class public static void method."); }}Copy the code

The subclass son. Java inherits from the parent class

public class Son  extends Father {
    public static String test = Subclass static variable;

    public static void test(a){
        System.out.println(Subclass static method); }}Copy the code

The second son son2.java also inherits from the parent class

public class Son2 extends Father {

    public static String test = "Second son static variable";

    public static void test(a) {
        System.out.println("Static method of second son"); }}Copy the code

The main Application class application.java:

public class Application {
    public static void main(String[] args) {
        Father father = new Father();
        Son son = new Son();
        Son2 son2 = new Son2();

        System.out.println(father.test);
        System.out.println(son.test);
        System.out.println(son2.test);
        System.out.println("-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --"); father.test(); son.test(); son2.test(); Father.test(); }}Copy the code

Output result:

Analysis of the

A class has only one space for static objects, so its output differs from that of its parent class.

If a class does not “override” a static method from its parent class, it inherits it. In the main program class, we can call static variables and methods directly from the parent class, and print the content that the parent class writes.

conclusion

A subclass can inherit static methods from its parent class, but cannot override them. The result is different because the subclass also creates a space for its own static variables and methods, which is equivalent to writing a subclass-specific method that is static.

Proof of this: in a subclass, adding @override to the “Override” static method will compile an error:

A method does not override methods in its superclass. Static (test); static (test); static (test);