继承中的静态方法 [英] Static method in inheritance

查看:32
本文介绍了继承中的静态方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

class A
{
    static{
        get();
    }
    static void get(){
        System.out.println("HELLO");
    }
}

class B extends A
{
    public static void main(String[] args) {

    }
}

输出:

你好

A 类的静态方法是如何被调用的.我可以理解 B 被调用的静态方法,但不能理解 A 的静态方法.

How is static method of class A getting called. I can understand static method of B getting called but not of A.

推荐答案

因为 B 继承自 A,如果 B 类被加载,那么 A 类必须被加载,如果它被加载,它的静态初始化块必须被称为.

Because B extends from A, if the B class is loaded, then the A class has to get loaded, and if it is loaded, its static initializer block must be called.

这篇关于继承中的静态方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆