what is difference between
String s=new String("vali");
String s="vali"

Answer Posted / kartik sharma

In case of String s=new String("vali"); , a memory in the heap is allocated to the variable of the class String, and then the value is given to the variable s="vali". Using new operator , we can allocate the memory to the instance of the class.


But in String s="vali" , only the variable s is given the value as vali but there is no permanent memory given to the variable in heap.

Is This Answer Correct ?    6 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why do we use encapsulation in oops?

522


What is static modifier?

631


Can you inherit a private class?

631


class CTest { public: void someMethod() { int nCount = 0; cout << "This is some method --> " << nCount; } }; int main() { CTest *pctest; pctest->someMethod(); return 0; } It will executes the someMethod() and displays the value too. how is it possible with our creating memory for the class . i think iam not creating object for the class. Thanks in Advance... Prakash

1698


Is abstract thinking intelligence?

594






How can you overcome the diamond problem in inheritance?

768


Can we have inheritance without polymorphism?

613


What is cohesion in oop?

624


Why interface is used?

553


write string class as your own class in java without using any built-in function

1976


What is byval and byref? What are differences between them?

1689


IS IT NECESSARY TO INITIALIZE VARIABLE? WHAT IF THE INSTANCE VARIABLE IS DECLARED final ? IS IT NECESSARY TO INITIALIZE THE final VARIABLE AT THE TIME OF THEIR DECLARATION?

1581


Where You Can Use Interface in your Project

1427


What does and I oop and sksksk mean?

652


What is the highest level of cohesion?

579