Java Interview 1

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.