0
Why are Java high level classes and interfaces be declared just public and default
Hi, I am new to java and want to understand why can we declare high level classes, interfaces and enumeratiom just public and default? . Why not protected or private? . Many thanks in advance
4 Answers
0
what do you mean with a high level class?
Interface is an easy one.
If you look from a software design perspective its obvious why there are no private interfaces.
As the name states, an Interface describes the "interface" to your class. When you dont know anything about a class, you have to know at least the interface. Otherwhise you wouldnt be able to use or communicate with that class.
If you want a "private" Interface, just don't use one.
If you fully understand OOP, encapsulation and so on this is a no brainer ;-)
As for enums, you can have private enums.
0
By high level classes, interface and enums I mean that are not enclosed by any other classes, interfaces or enums
0
well, just answer this question:
For what or how would you use something like this?
You see, you cannot use it at all.
- 1
Interface is an easy one.
If you look from a software design perspective its obvious why there are no private interfaces.
As the name states, an Interface describes the "interface" to your class. When you dont know anything about a class, you have to know at least the interface. Otherwhise you wouldnt be able to use or communicate with that class.
If you want a "private" Interface, just don't use one.
If you fully understand OOP, encapsulation and so on this is a no brainer ;-)
As for enums, you can have private enums