-1

I am reading Java: The Complete Reference, Eleventh Edition, 11th Edition by Herbert Schildt and couldn't really understand what the author mean by the following text:

When it is declared as public, the interface can be used by code outside its package. In this case, the interface must be the only public interface declared in the file, and the file must have the same name as the interface.

Nitin Singla
  • 106
  • 2
  • 9

2 Answers2

0

it's not just interfaces,

by default, if you have declared a public class in a file, the file and the class should both have the exact same name, and public 'things' can be used from everywhere, not like 'package-private' which is the default java access modifier if you didn't provide one, it allows your classes to be visible only in the package they are in.

Mahmoud Farouq
  • 423
  • 1
  • 3
  • 13
0

It's a design decision by the original authors of Java. By making that explicit, packaging and modularization are always reflected in the directory tree of the sources, and vice versa.

One might question that decision — I do, it means that you can't refactor packaging without breaking the code all over the code base — but that's what did it.

Charlie Martin
  • 110,348
  • 25
  • 193
  • 263