Panax Notoginseng , the following statement altogether created how many objects:strings= "a" + "B" + "C" + "D";
Answer: For the following code:
STRINGS1 = "a";
STRINGS2 = S1 + "B";
STRINGS3 = "a" + "B";
SYSTEM.OUT.PRINTLN (s2== "AB");
system.out.println (s3== "AB");
The first statement prints the result false The second statement prints the result of true javac compilation can be optimized for expressions that add directly to string constants without having to wait for the runtime to do addition processing, but rather to compile with the plus sign removed, compiling it directly into a result of these constants.
The first line of code in the title is optimized by the compiler at compile time, which is equivalent to defining a " ABCD " So the above code should only create a string object. Write the following two lines of code,
Strings = "a" + "B" + "C" + "D";
System.out.println (s== "ABCD");
The result of the final printing should be true .
Java Interview 1