Java
Programming and Technical
Programming
What is the output of the following program?
import java.util.Arrays;
class Test
{
public static void main(String args[])
{
String[] cities = new String[]{"London", "Paris", "NewYork", "HongKong", "Tokyo"};
String[] metros = new String[]{"London", "Paris", "NewYork", "HongKong", "Tokyo"};
String[] capitals = cities;
System.out.println("cities == metros : " + (cities == metros));
System.out.println("cities == capitals : " + (cities == capitals));
System.out.println("cities.equals(metros) : " + cities.equals(metros));
System.out.println("cities.equals(capitals) : " + cities.equals(capitals));
System.out.println("Arrays.equals(cities, metros) : " + Arrays.equals(cities, metros));
System.out.println("Arrays.equals(cities, capitals) : " + Arrays.equals(cities, capitals));
}
}
A. cities == metros : false
cities == capitals : true
cities.equals(metros) : true
cities.equals(capitals) : true
Arrays.equals(cities, metros) : false
Arrays.equals(cities, capitals) : true
B. cities == metros : false
cities == capitals : true
cities.equals(metros) : true
cities.equals(capitals) : true
Arrays.equals(cities, metros) : true
Arrays.equals(cities, capitals) : true
C. cities == metros : false
cities == capitals : true
cities.equals(metros) : false
cities.equals(capitals) : true
Arrays.equals(cities, metros) : true
Arrays.equals(cities, capitals) : true
D. cities == metros : false
cities == capitals : true
cities.equals(metros) : false
cities.equals(capitals) : true
Arrays.equals(cities, metros) : true
Arrays.equals(cities, capitals) : false
Read Solution (Total 1)
-
- C. cities == metros : false
cities == capitals : true
cities.equals(metros) : false
cities.equals(capitals) : true
Arrays.equals(cities, metros) : true
Arrays.equals(cities, capitals) : true - 1 Month agoHelpfull: Yes(0) No(0)
Java Other Question