为什么子类可以访问具有内部类的超类的私有成员?

Why does a subclass have access to a private member of the superclass with inner classes?

    public class Main {
    static class Article {
        // Price in Article, private!
        private float price;

        Article(float price) {
            this.price = price;
        }
    }

    static class Milk extends Article {

        Milk(float price) {
            super(price);
            //Has access to private price
            System.out.println(super.price);
        }
    }

    public static void main(String[] args) {
        new Main.Milk(1.5f);

    }
}

在此示例中,子类可以通过 super.price 访问私有成员 access specifiers in inner classes是什么意思?

来自JLS 6.6.1

Otherwise, the member or constructor is declared private, and access is permitted if and only if it occurs within the body of the top level type (§7.6) that encloses the declaration of the member or constructor.

嵌套的 class 因此可以访问其顶级 class 的私有成员,反之亦然。出于所有实际目的,私有成员可以在当前 .java 文件中准确访问。