If a constructor is the only way to create the object of a class then how String name = "Java"; is able to create an object of String class even without using constructor.
No. Constructor is not the only way.
There are at least two more ways:
Though in case with your example - neither of these is used.
In this case Java uses string pool
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With