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 causes polymorphism?
Write a program to compute for numeric grades for a course. The course records are in a file that will serve as the input file. The input file is in exactly the following format: Each line contains a student's first name, then one space, then ten quiz scores all on one line. The quiz scores are in whole number and are separated by one space. Your program will take it input from this file and sends it output to a second file. The data in the output file will be exactly the same as the data in the input file except that there will be one additional number (of type double) at the end of each line. This number will be the average of the student's ten quiz scores. Use at least one function that has file streams as all or some of its arguments.
What is encapsulation example?
when to use 'mutable' keyword and when to use 'const cast' in c++
Can a destructor be called directly?
What is ambiguity in inheritance?
What is polymorphism and why is it important?
What is oops with example?
What is a class oop?
which feature are not hold visual basic of oop?
What is the purpose of enum?
Why multiple inheritance is not allowed?
What is the example of polymorphism?
What is the main purpose of inheritance law?
What is destructor in oop?