About java parent and child attributes with the same name

The properties of the same name of the parent and child classes are not directly overwritten, but exist in different domains. The static reference is whose property is the last one to be accessed. To set or get access to the property of the parent class, use super

Kang Kang others

The rewriting of static methods is binding static references
Insert picture description here

public class TT {
    
    
    public static void ss(){
    
    
        System.out.println("f");
    }
    public static void main(String[] args) {
    
    
        TT.ss();
        S.ss();
        TT s=new S();
        s.ss();
    }
}

class S extends TT{
    
    
    public static void ss(){
    
    
        System.out.println("s");
    }
}

As a result,
static methods are only related to static classes, S hides the static methods of the parent class,
and the binding of s should be the TT class when compiled.
Insert picture description here

Guess you like

Origin blog.csdn.net/qq_36976201/article/details/108876514