what is the difference between :
String s1;
And
String s1 = new string();
How does the memory operate?
what is the difference between :
String s1;
And
String s1 = new string();
How does the memory operate?
String s1;
Is either:
s1
without first assigning a value will result in a compilation error.null
).String s1 = new String();
Is a variable or field initialized to an empty string;
The first declares an identifier or field for later use, while the second allocates and assigns a value (empty string) to the identifier.