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 is OOPS and How it is different from Procedural Programming ?

23 Answers   HP, Infosys, Thyrocare,


What do you mean by multiple inheritance and multilevel inheritance? Differentiate between them.

2 Answers  


what is overloading and overriding?

7 Answers  


Why do while loop is used?

0 Answers  


what is single inheritance?

18 Answers   IBM,


What do we mean by a hidden argument in a function?

1 Answers   TCL,


What language is oop?

0 Answers  


What is encapsulation?

17 Answers   TCS,


write a program that takes input in digits and display the result in words from 1 to 1000

0 Answers   Wipro,


What is object and class in oops?

0 Answers  


What is the difference between a constructor and a destructor?

0 Answers  


what is polymorpsim? what are its types?

8 Answers  


Categories