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

How many types of access specifier in c# and vb.net?

1 Answers   Infosys,


what is the use of template classes in c++

1 Answers  


Why is oop useful?

0 Answers  


Program to read a comment string

1 Answers   IBM,


what is data hiding.

3 Answers   Wipro,






You attempt to query the data base with this command: SELECT name, salary FROM employee WHERE salary=(SELECT salary FROM employee WHERE last name='Wagner' OR dept no=233) Choose most appropriate option from the following: 1)Sub-queries are not allowed in the where clause. 2)a multiple row sub-query used with a single row comparison operator. 3)a single row query is used with a multiple row comparison operator.

10 Answers   Zycus Infotech,


What do you mean by inheritance?

0 Answers   IBS,


what is namespace? what are the uses of namespace?

1 Answers  


JAVA is FULLY OBJECT ORIENTED PROGRAMING LANGUAGE?

3 Answers  


Why and when is a virtual destructor needed?

5 Answers  


How is data security provided in Object Oriented languages? ?

5 Answers  


How is class defined?

0 Answers  


Categories