0 votes
in JAVA by
In which memory a String is stored, when we create a string using new operator?

a) Stack

b) String memory

c) Heap memory

d) Random storage space

1 Answer

0 votes
by

(c) Heap memory

Reason: When a String is created using a new operator, it always created in the heap memory. Whereas when we create a string using double quotes, it will check for the same value as of the string in the string constant pool. If it is found, returns a reference of it else create a new string in the string constant pool.

Related questions

0 votes
asked Apr 10, 2021 in JAVA by Robindeniel
0 votes
asked Apr 9, 2021 in JAVA by Robindeniel
...