Why are Java high level classes and interfaces be declared just public and default | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
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

28th Dec 2016, 7:19 PM
Hasnat Saeed
Hasnat Saeed - avatar
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.
29th Dec 2016, 12:38 PM
Roland
0
By high level classes, interface and enums I mean that are not enclosed by any other classes, interfaces or enums
29th Dec 2016, 7:38 PM
Hasnat Saeed
Hasnat Saeed - avatar
0
well, just answer this question: For what or how would you use something like this? You see, you cannot use it at all.
30th Dec 2016, 9:30 AM
Roland
- 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
6th Feb 2017, 1:06 PM
kumar abhishek
kumar abhishek - avatar