It depends. The question is not clear enough to give a yes/no answer in my opinion.
If the application somehow exposes the variable then, naturally, other applications can just ask to get the value. But this is unlikely what the question was supposed to target. But keep it in mind. In interviews, I found it always good to prove that you can think critically and outside of the box.
I guess they wanted to see if you had grasped the concept of static variables and ClassLoader
s. A Java application is dynamically linked which means that at runtime, a ClassLoader
(which depends on the application) will perform the linking, loading all libraries or delegating the loading. Static variables are referred to by class. If you try to access a static variable, the class' ClassLoader
will try to find and load the class. As each application has its own ClassLoader
, each application has its own set of variables.
This is not unlike the principle of separation of address space found in older languages. An application runs in a separate address space even if it is hosted by the same machine. Therefore, two applications running alongside each other cannot simply address variables in the other application's address space as it would violate a constraint that is enforced by several watchdogs. But beware, address space can be shared explicitly.