String is a immutable objects . it means that string does
not change...........
But it will be chang.........
{
String s="kapil";
String s1="raj";
String s=s1;
then print(.......)
The String has been changed ..
how it is possible and why its called immutable objects
Answer Posted / anil kumar khichar
Immutable means the original String never get changed or
replaced by another one. You can simply concate another one
, but beware you can't replace it. Look at the following:-
{
String s="kapil";
String s1="raj";
String s=s1;
see here if you assign s1 to s ,there will you get error.
And it's not allowed here. So we can say Strings are immutable.
Thanks!
Anil
| Is This Answer Correct ? | 1 Yes | 4 No |
Post New Answer View All Answers
How do you declare a variable?
What are the two basic ways in which classes that can be run as threads may be defined?
What is the difference between member variables initialization and assignment in a constructor?
What are green threads in java?
What interface is extended by awt event listeners?
how do I create a runnable with inheritance? : Java thread
Can I declare class as static or private?
What is difference between adapter class and listener?
Explain inheritance in java?
Why pointers are not used in java?
What is a container in a gui?
How do you add an element to a set in java?
Can inner class have constructor?
What is merge sort in java?
What is the syntax and characteristics of a lambda expression? Explain