Run this simple java program and create scenerio of String object creation in your mind.You will see huge difference than expectation. I would recommend to first try on your own then follow the solution . As you execute the above line of codes in your Java Runtime Environment .As compiler read the lines .In case of String a= new String("Hello"); As it will allow compiler to create a new string object .It is always mandatory for compiler to allocate a memory space in heap whenever new keyword is used.So String class object created successfully in heap with reference variable a.And a very important point need to be noted down that here "new String("Hello');" ...
“Give a man a program, frustrate him for a day. Teach a man to program, frustrate him for a lifetime.” ― Waseem Latif
Comments
Post a Comment