-3

What is the difference between Public and Protected in Java? According to the Oracle documentation available here https://docs.oracle.com/javase/tutorial/java/javaOO/accesscontrol.html, Public is also available to the World while Protected is not. Now, I cannot understand what 'World' means here. Can anybody clarify, please? Thanks, Alberto

  • What does that documentation say about `protected` (beside what it is not)? – ernest_k Jan 20 '20 at 14:27
  • 1
    There are plenty of other resources available to explain this. If the Oracle tutorials aren't doing it for you, there are at least a hundred other explanations. You shouldn't need to ask for a 101st. – Michael Jan 20 '20 at 14:33
  • I could not understand what they meant with the word 'World'. Public means that any class in the package can access (the code in) a class declared as Public, ok, but why use the word World? It made me understand that, somehow, any other program written in Java could access the code of that class declared as Public but present in another program, while with Protected this would not happen. – Giulio Severini Jan 20 '20 at 15:17

2 Answers2

0

World is whole your program. For example, with protected modifier, fields/methods would not be accessible from other packages, and with public modifier, you could access them.

devNNP
  • 59
  • 4
  • Ok, so with the word World they mean the entirety of the packages that make up a program. Ok, thanks, that's what I could not understand. – Giulio Severini Jan 20 '20 at 15:18
0

Public = Everyone can see it.

Protected = Package Private + can be seen by subclasses or package members.

World = All code in the application, regardless where it is.

muellerra
  • 64
  • 1
  • 3