| preferred AP College board partner for AP classes
easy Solved by 2 students
String Object Comparison in Java
< Prev
Next >

Consider the following code segment.

public class StringCheck {
    public static void main(String[] args) {
        String fruit = new String("apple");
        if(fruit == "apple")
            System.out.println("They match!");
        else
            System.out.println("They do not match!");
    }
}

The program produces the output They do not match!. Which of the following statements best explains this result?

A

Creating the String object with new instead of a string literal.

B

Omitting parentheses around the if condition.

C

Using “==” instead of the equals() method for string comparison.

D

Misspelling the string literal.

Hint
Did You Know?
Explain Why
Explain All Answers
Check Answer
Show Correct Answer
Report Question

Question Leaderboard

Rank
User
Correct Count
Attempt Count
Time
Score
#1ahsan4810522 0m 00s 200
#2the.ronzono11 0m 00s 100
#3yekeon051501 0m 00s -10
#4psak1201 0m 33s -43
Items per page:
10
1 – 4 of 4
No comments yet. Be the first to comment!

AI Tutor

How can I help?

APFIVE © 2020.
Email: apfive@apfive.org|Privacy Policy