what is difference between
String s=new String("vali");
String s="vali"
Answer Posted / 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 View All Answers
What is polymorphism and its types?
i am getting an of the type can not convert int to int *. to overcome this problem what we should do?
Why is polymorphism needed?
Why can't we have instance(stack) of a class as a member of the same class like eg.Class A{A obj;} as we can have self refential pointer
Why is it so that we can have virtual constructors but we cannot have virtual destructors?
What is super in oop?
What is difference between abstraction and encapsulation?
What is encapsulation in ict?
What is abstract class in oop?
What is the oops and benefits of oops programming?
Can you explain polymorphism?
What is the difference between encapsulation and polymorphism?
What is overloading in oop?
What is the point of polymorphism?
What is destructor give example?