Simple question I hope
Consider 2 the two following files in the same folder:
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());
}
}
No packages are declared, and the two shape class implementations are not listed as public packages, so why is this compiling? I would have thought that Square and Triangle classes wouldn't be visible to App. If I label them package A and package b, they can't see each other, as expected. Does the compiler consider 2 files in the same folder with no package declaration to be in the same package by default?