String count in the pool with println

后端 未结 2 1062
你的背包
你的背包 2021-01-11 12:01

I am preparing for the OCA SE 7 exam, and some of these questions are really (!) tricky.

In one of the books Im using I found an error I think, so I would like to co

2条回答
  •  终归单人心
    2021-01-11 12:57

    true and false are not String objects, so they do not count. Even though the exam questions are supposed to be tricky, it's goal is to check the understanding of general concepts. Which is in this case: during class loading (before running), the string literals are loaded to the constant pool. So "autumn" and "summer" will be in the constant pool.

    It is described here nicely: http://www.javaranch.com/journal/200409/ScjpTipLine-StringsLiterally.html

提交回复
热议问题