Strings vs classes when both are reference types

后端 未结 4 2055
北荒
北荒 2021-02-02 00:07

Here is how my last interview went:

Question: Where are strings stored?

Answer: Heap since it is a reference type

4条回答
  •  名媛妹妹
    2021-02-02 00:48

    Strings share buffer. In your case if one and two were strings, they would be separate objects (two objects on the heap), but internally they would point to the same buffer (third object on the heap).

提交回复
热议问题