What does it mean for a String in Java to be immutable?
Immutable Strings in java basically means once a String is created, the String object cannot be changed no matter what. However, the reference to the String object can be changed. For example: String s = "some string"; //created an immutable string object. s variable references the object s = "a new string"; //created another immutable string object. s variable drops reference to "some string" object and now references "a new string" object
What is the output of the following code snippet? int number= 5; cout << number++ << endl;
Output: 5 The output is 5 because number is initialized to 5, and is only incremented after the cout line because number++ means number is incremented afterwards. If on the other hand we were to replace number++ with ++number, the output would be 6 because ++number means number is incremented beforehand.
Any program that can be completed via while loop can also be completed via for loop