Exam 1z0-829 All QuestionsBrowse all questions from this exam
Question 18

Given the code fragment:

What is the result?

    Correct Answer: D

    The first comparison (myStr.equals(myTextBlk1)) evaluates to true because the content of myStr and myTextBlk1 is the same, ignoring the way they are defined. The second comparison (myStr.equals(myTextBlk2)) is false because myTextBlk2 contains a trailing newline character, making it different from myStr. The third comparison (myTextBlk1.equals(myTextBlk2)) is also false for the same reason - the additional newline character in myTextBlk2. The final comparison (myTextBlk1.intern() == myTextBlk2.intern()) is false because interning strings with different content (due to the newline character in myTextBlk2) results in different references.

Discussion
c6437d5Option: D

D tested correct

supersquaxOption: D

right option is D. copy paste into https://editor.javadevjournal.com/java-17-compiler.html and see for yourself: public class Main{ public static void main(String[] args){ String myStr = "Hello Java 17"; String myTextBlk1 =""" Hello Java 17"""; String myTextBlk2 =""" Hello Java 17 """; System.out.print(myStr.equals(myTextBlk1)+":"); System.out.print(myStr.equals(myTextBlk2)+":"); System.out.print(myTextBlk1.equals(myTextBlk2)+":"); System.out.println(myTextBlk1.intern() == myTextBlk2.intern()); } }

meltedoliveOption: D

right option is D.

xplorerpjOption: D

D is correct answer

Bharadwaj240796Option: D

Option D. true:false:false:false is correct!!

testostawsOption: A

Prints true:false:false:false The first comparison is true because myStr and myTextBlk1 are equal (text block doesn't include trailing new lines if there is no content after the last quote). The second and third comparisons are false because myTextBlk2 includes a newline character at the end, making it different from myStr and myTextBlk1. The last comparison is false because, despite interning, myTextBlk1 and myTextBlk2 are not equal due to the newline character in myTextBlk2.

TojoseOption: C

I think the right option is C. true:false:true:true