I found the following program puzzling:
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 Java allows public class B
to extend private class A
? In other languages e.g. C# class may only extend private class when it is private itself.
Can you provide any scenario when extending private class may be useful?