‹ Back to the paper
Find the output of the following snippet: void check1( ) { String x[ ] = {"Kolkata", "Chennai"…
Find the output of the following snippet:
void check1( )
{
String x[ ] = {"Kolkata", "Chennai", "Delhi"};
String y[ ] = {"Kolkata", "Chennai", "Delhi"};
System.out.println(x.equals(y));
}Answer
Answer
AIfalse
Arrays do not override equals( ), so x.equals(y) uses the default Object.equals( ), which compares object references (memory addresses), not contents; since x and y are different array objects, it returns false even though their elements are equal.
From ISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024), question 43.