与重写类似,方法的重写是子类覆盖父类的对象方法 


隐藏,就是子类覆盖父类的类方法

父类:

public class Person {
    public String name;
    protected float hp;

    /**
     * 类方法,静态方法
     * 通过类就可以直接调用
     */
    public static void battlewin(){
        System.out.println("hero battle win");
    }
}

子类:


public class ADHero extends Person {
    public static void battlewin(){
        System.out.println("ad hero battle win");
    }

    public static void main(String [] args){
        Person.battlewin();
        ADHero.battlewin();

        Person person=new ADHero();
        person.battlewin();
    }
}



输出:

hero battle win
ad hero battle win
hero battle win

编译看左边,运行看右边,

person调用的类方法都是person的,ADHero调用的方法都是ADHero的。