Java Interview Questions - Instantiation

Here are the most popular Java interview questions about instantiation.

See all questions

When is memory allocated for static members?

All instantiation and memory allocation for static variables for all classes in the program is done before running the main method.

Are two Strings containing identical text always equal in every way, every time?

No. If the Strings are instantiated using the String constructor, then they will have the same value but will reference distinct, and therefore different, objects.


So, writing S1 == S2 will be false when either S1, S2, or both are created using the String constructor, because they are pointing to different objects. Using `S1.equa


Looking for developers?