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 |
What is object and class in oops?
what is oppes
How to hide the base class functionality in Inheritance?
What is virtual Function.
What is polymorphism? Explain with an example.
What is protected in oop?
why oops need in programming
How to overload new operator in c++
How do you make derived class as an abstract class?
Program to open a file with First argument
What is a null tree?
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)