Private class extension in Java

I found the following program puzzled:

package package1;

public class Main {
    private static class A { }

    public static class B extends A { }
}

// ----------------
package package2;


public class Test {
    public static void main(String[] args) {
        Main.B b = new Main.B();
    }
}

Why does Java allow a public class Bto extend a private class A? In other languages, for example. A C # class can only extend a private class when it is private.

Can you provide any scenario when distributing a private class?

+4
source share
2 answers

A ( ), ( B). B, , B , API. , B A , , ?.

, C, D, E, F .. A. A .

+1

, , , , onclick ..... , . , .

OCP.

0

Source: https://habr.com/ru/post/1664049/


All Articles