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

for example A,B,C,D are class all the 4 class contain one method who() but the method who() implementaion is differnet among each class. the relation among the 4 class are A is base class and is inherited by B and C.and from this two B and C where D is inherited. the question is i want to display the output who() method in all the classes(A,B,C,D)the output of who() method is diferrent amond all the class(A,B,C,D) ------A------ virtuval who(print a) override | | who(print b) B C override who(print c) | | -------D------ override who(print d)

2 Answers  


• What are the desirable attributes for memory managment?

0 Answers  


what are the ways in which a constructors can be called?

2 Answers   TCS,


difference between static and non-static variables?

2 Answers  


Can you explain polymorphism?

0 Answers  






What is the full form of oops?

0 Answers  


what is the function of 'this' operator ?

7 Answers   Wipro,


Where is pseudocode used?

0 Answers  


Difference between over loading and over ridding?

12 Answers   CTS, Patni, Softvision Solution,


Whatis the difference between oop and object based language

3 Answers  


write a progra in c++ using class & object to find out wheather a given no. is prim or not.

2 Answers  


What is destructor example?

0 Answers  


Categories