PRASHNIKAप्रश्निका
‹ Back to the paper

Find the output of the following snippet: void check1( ) { String x[ ] = {"Kolkata", "Chennai"…

Computer Science20251 markShort answer
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

AI
false 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.
Arrays, Strings

From ISC Computer Science - Competency Focused Practice Questions (CISCE, August 2024), question 43.