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 object and class in oops?

0 Answers  


what is oppes

2 Answers  


How to hide the base class functionality in Inheritance?

0 Answers   Viscus Infotech,


What is virtual Function.

1 Answers   Wipro,


What is polymorphism? Explain with an example.

48 Answers  






What is protected in oop?

0 Answers  


why oops need in programming

7 Answers   TCS,


How to overload new operator in c++

2 Answers  


How do you make derived class as an abstract class?

1 Answers   Convergys, TCS,


Program to open a file with First argument

1 Answers   TCS,


What is a null tree?

0 Answers  


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  


Categories