exam questions

Exam 1z0-808 All Questions

View all questions & answers for the 1z0-808 exam

Exam 1z0-808 topic 1 question 207 discussion

Actual exam question from Oracle's 1z0-808
Question #: 207
Topic #: 1
[All 1z0-808 Questions]

Given:
and the code fragment:

What is the result?

  • A. AC
  • B. BD
  • C. BC
  • D. AD
Show Suggested Answer Hide Answer
Suggested Answer: C 🗳️

Comments

Chosen Answer:
This is a voting comment (?). It is better to Upvote an existing comment if you don't have anything to add.
Switch to a voting comment New
7df49fb
3 months, 3 weeks ago
There is a problem with the question, i think the answer is AC. because (s1 == "Moon") && (s2.equals("Moon")) evaluate to true.
upvoted 1 times
...
cocobot
9 months, 2 weeks ago
Selected Answer: C
Answer is C, as although it looks like the OraString is overriding the equals method. But its actually just a method as the Objects equals method required Object as the parameter. Hence the second statement of if((s1 == "Moon") && (s2.equals("Moon"))) evaluates to false.
upvoted 1 times
...
carloswork
1 year, 8 months ago
Selected Answer: C
Answer is C. To test: class OraString { String s; public boolean equals (OraString str) { return this.s.equalsIgnoreCase(str.toString()); } OraString(String s){ this.s = s; } } public class Test { public static void main(String[] args) { String s1 = "Moon"; OraString s2 = new OraString("Moon"); if((s1 == "Moon") && (s2.equals("Moon"))) { System.out.println("A"); } else { System.out.println("B"); } if (s1.equalsIgnoreCase(s2.s)) { System.out.println("C"); } else { System.out.println("D"); } } }
upvoted 1 times
...
iSnover
1 year, 9 months ago
Selected Answer: C
The answer is the letter C, even though I try the same content, strings are different if they are parsed as "==" or something like that because they are not primitive types. The correct way to compare the contents of String and different objects is equals and its variegated. Right in the first if of false (B) and in the second if of true (C), printing BC.
upvoted 1 times
...
Community vote distribution
A (35%)
C (25%)
B (20%)
Other
Most Voted
A voting comment increases the vote count for the chosen answer by one.

Upvoting a comment with a selected answer will also increase the vote count towards that answer by one. So if you see a comment that you already agree with, you can upvote it instead of posting a new comment.

SaveCancel
Loading ...
exam
Someone Bought Contributor Access for:
SY0-701
London, 1 minute ago