what is the difference between String s="hello"; and String
s=new String("hello");?

Answer Posted / amit singh

when you put String s = new String(null)
you will get the thing waht i'm trying to say that
beacuse my english is weak so what i'm trying to say
understatd
beacuse there is no realtion between the
1)which is for literal
2)which is for new String()
don't add both at the same time
because both are different question itself and different
answer itself.
but you will connect that then the problem is your own so
please
if you try to add both the thing is comeup
throug the itself that the hello string in a pool for the
first statement
so for the second String s = new String("hello");
compiler go to the pool and and check that "hello" it is
present if it present then it will pick it through the pool
and assign it to the overloaaded constructor of the String
class which will take the String(string s)so new operator
creates new object which will contain the hello.
and the the new String object will create so please check
to put String s = new String(null)
you will get ambiguous error
overloaded constructor in String class
String(String s) and String(StringBuffer s) and many
and you will get what i'm trying to say so do't add
ist STATEMENT TO SECOND WHICH IS FOR NEW STRING()
thanks
amitsing2008@gmail.com

Is This Answer Correct ?    1 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How to change the priority of thread or how to set priority of thread?

559


Which programming language is best in future?

517


What is the difference between abstraction and encapsulation?

556


What are the features of java?

527


What is this keyword used for?

680






Can we overload the constructors?

555


whatis Home interface and Remoteinterface? with example?

1539


What is arguments in java?

516


How many characters is 2 bytes?

524


How do you achieve singleton?

526


Why charat is used in java?

534


How does regex work?

517


Tell me are there implementations for sorting and searching in the java libarary?

592


Can a abstract class be declared final?

560


What is the program development process?

557