1).what is the difference between below examples

String s="vijay";

String s=new String("vijay");

Answer Posted / navneet raushan

the first case does: if u write first case , one object and
one refernce will be created. object will be created in
string pool.
But when u write 2nd case , two object and one refernce
will be created , one in string pool and one in heap.

Is This Answer Correct ?    1 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What are the different http methods?

516


What is the purpose of abstract class?

511


how to create multithreaded program? Explain different ways of using thread? When a thread is created and started, what is its initial state? : Java thread

520


What is a private class in java?

499


What is the purpose of the enableevents() method?

569






What is the difference between the font and fontmetrics classes in java programming?

484


List some important features of java 10 release?

501


What are white spaces in java?

510


What is immutable state?

492


Is there a sort function in java?

567


What is private static in java?

565


What is a text string?

609


How do I know if java is installed?

504


What is the purpose of the strictfp keyword?

600


Is empty string in java?

522