OCA Java SE 8 Mock Exam 2 - OCA Mock Question 4








Question

Given the following code, which expression displays the word "Equal"?

         String s1="Java"; 
         String s2="java"; 
         if(expression) { 
            System.out.println("Equal"); 
         } else { 
            System.out.println("Not equal"); 
         } 
  1. s1==s2
  2. s1.matchCase(s2)
  3. s1.equalsIgnoreCase(s2)
  4. s1.equals(s2)




Answer



C

Note

A compares equality of object reference.

B is incorrect because there is no method as matchCase.

D uses the equals method with the case which is different in the two strings.