Multiple choice technology programming languages

What will be the output of the below code snippet? public class Quiz3 { public static void main(String args[]) { final String pig = "length: 10"; final String dog = "length: " + pig.length(); System.out.println("Animals are equal: " + pig == dog); } }

  1. True

  2. False

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

In Java, the + operator has higher precedence than the == operator. The expression evaluates as ("Animals are equal: " + pig) == dog. This compares a newly created concatenated string to dog, resulting in false.