12.9 String object by using new operator
Case 4:String s1 = new String("Java");
- We are using new operator to create a String object, here JVM will create two objects, one is in heap memory which is assigned with reference and another object will be in SCP memory without reference.
- new : For s1 one object will be created and assign that object with s1 reference.
----------------------------------------------------------------------------
Case 5: String s1 = new String("Java");
String s2 = new String("Html");
- We are using new operator to create a String object, here JVM will create two objects, one is in heap memory which is assigned with reference and another object will be in SCP memory without reference.
- new : For s1 one object will be created in Heap memory and assign that object with s1 reference, another object will be created in SCP memory without reference.
- new : For s2 one object will be created in Heap memory and assign that object with s2 reference, another object will be created in SCP memory without reference.
----------------------------------------------------------------------------
Case 6:
String s1 = new String("Java");
String s2 = new String("Html");
String s3 = new String("Java");
- We are using new operator to create a String object, here JVM will create two objects, one is in heap memory which is assigned with reference and another object will be in SCP memory without reference.
- new : For s1 one object will be created in Heap memory and assign that object with s1 reference, another object will be created in SCP memory without reference.
- new : For s2 one object will be created in Heap memory and assign that object with s2 reference, another object will be created in SCP memory without reference.
- new : For s3 one object will be created in Heap memory and assign that object with s3 reference, another object will not created in SCP memory because already object(Java) is available.
----------------------------------------------------------------------------
Thanks for your time.
Thanks for your time.
Nireekshan