+ 7

How many objects are created in the below == > String s = new String("Welcome");

String s = new String("Welcome"); Hit like and post your answer

27th Dec 2016, 6:42 PM
Jenny Lance
Jenny Lance - avatar
8 Antworten
+ 13
Trust Me..it's proved The correct answer is 2 Objects created. 1st Object== "Welcome" is a String literal and every String literal itself is an Object in Java. 2nd Object== String class Object created using new String () The first Object "Welcome" is created in STRING CONSTANT POOL and one more "Welcome" Object is stored outside the POOL.
27th Dec 2016, 8:07 PM
Jenny Lance
Jenny Lance - avatar
+ 5
This is a tricky question many people failed to answer it correctly..
27th Dec 2016, 6:39 PM
Jenny Lance
Jenny Lance - avatar
+ 3
1?
27th Dec 2016, 6:36 PM
Valen.H. ~
Valen.H. ~ - avatar
+ 3
Welcome is picked up from constant pool using ldc, and the String constructor is called
29th Dec 2016, 12:53 PM
Suvaditya
Suvaditya - avatar
+ 1
closer to self taught badge ;)
28th Dec 2016, 1:38 AM
seamiki
seamiki - avatar
+ 1
2
30th Dec 2016, 5:33 PM
uday chafale
uday chafale - avatar
0
1
27th Dec 2016, 8:01 PM
Tarviha Fatima
Tarviha Fatima - avatar
- 1
There are 2 objects for sure.
5th Jan 2017, 2:33 AM
Gaurang Mudgal
Gaurang Mudgal - avatar