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



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

Answer / 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

More OOPS Interview Questions

What are the fields of vtable

1 Answers   Mphasis,


Can you name some types of inheritance?

3 Answers   Motorola,


What do you mean by overloading?

0 Answers  


pointers are support in C#? if yes then how to use it?

8 Answers   Softvision Solution,


what is the difference between class and object?

9 Answers  






What is difference between polymorphism and inheritance?

0 Answers  


What will happen when the following code is run: int x; while(x<100) { cout<<x; x++; } 1) The computer will output "0123...99" 2) The computer will output "0123...100" 3) The output is undefined

7 Answers  


what is virtual function in c++

6 Answers  


What is polymorphism in oops?

0 Answers  


what is polymorphism?

4 Answers  


what is the definition of incapsulation

2 Answers  


how to write a java program for an output ****0 ***01 **012 *0123 01234

1 Answers  


Categories