为什么 Java 编译器认为没有相同包声明的 2 个文件在同一个包中?

Why is Java compiler considering 2 files that don't have the same package declaration to be in the same package?

我希望是简单的问题

考虑 2 同一文件夹中的以下两个文件:

Shape.java

public abstract interface Shape { 
    public abstract double area();
    public abstract double perimeter();
    public default String getName() {
        return "default";
    }
}

class Square implements Shape {
    public static void visible() {
        System.out.println("Visible");
    }

    public double area() {
        return 0.00;
    }

    public double perimeter() {
        return 0.00;
    }

    public String getName() {
        return "square";
    }
}

class Triangle implements Shape {
    public double area() {
        return 0.00;
    }

    public double perimeter() {
        return 0.00;
    }

    public String getName() {
        return "triangle";
    }
}

App.Java

public class App {
public static void main(String... args) {
    Shape square = new Square();
    Shape circle = new Triangle();
    Square.visible();
    System.out.println(square.getName());
    System.out.println(circle.getName());
}

}

没有声明包,两个形状 class 实现没有列为 public 包,那么为什么要编译?我本以为 Square 和 Triangle classes 对 App 是不可见的。如果我将它们标记为 A 包和 B 包,它们将无法像预期的那样看到对方。默认情况下,编译器是否认为同一文件夹中没有包声明的 2 个文件位于同一包中?

它们都在同一个“默认”包中。没有包声明意味着使用默认的未命名包。