On running, it prints "s6 and s7 are same". But if i remove the final modifier of s1 and s2 then it's not. What could be the reason?
posted 3 years ago
Welcome to the Ranch
If you mark the String as final, then your catenation becomes a constant expression, (also called compile‑time constant) and is eligible for automatic entry to the String pool.
If you take the final modifier away, it ceases to be a constant expression.