解释静态类的行为何时继承?

时间:2019-07-18 03:39:24

标签: java static

我有一个名为StaticTestStaticInherited extends StaticTest的类,我想在StaticTest.A类中使用StaticInherited类,但是它说类型不兼容。

class StaticTest {

    static  class A{
        int a = 10;
        int getA(){
            return a;
        }
    }
}

public class StaticInherited extends StaticTest{

    static class A{
        int a = 20;
    }

    public static void main(String[] args) {
        StaticTest.A x = new StaticTest.A();
        System.out.println(x.a);

        StaticInherited.A y = new StaticInherited.A();
        System.out.println(y.a);

        StaticInherited.A z = new StaticTest.A();

        System.out.println(z.a);
    }

 }

0 个答案:

没有答案