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
Why do we use encapsulation in oops?
What is static modifier?
Can you inherit a private class?
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
Is abstract thinking intelligence?
How can you overcome the diamond problem in inheritance?
Can we have inheritance without polymorphism?
What is cohesion in oop?
Why interface is used?
write string class as your own class in java without using any built-in function
What is byval and byref? What are differences between them?
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?
Where You Can Use Interface in your Project
What does and I oop and sksksk mean?
What is the highest level of cohesion?