Java OCA OCP Practice Question 387

Question

What will be the result of attempting to compile and run the following program?

public class Main{ 
   public static void main (String args [] ){ 
      String s = "hello"; 
      StringBuilder sb = new StringBuilder ( "hello" ); 
      sb.reverse (); //  w w  w . j  a v  a 2 s . c o m
      s.reverse (); 
      if ( s == sb .toString () )  
          System.out.println ( "Equal" ); 
      else 
          System.out.println ( "Not Equal" ); 
    } 
} 

Select 1 option

  • A. Compilation error.
  • B. It will print 'Equal'.
  • C. It will print 'Not Equal'.
  • D. Runtime error.
  • E. None of the above.


Correct Option is  : A

Note

A. is correct. There is no reverse() method in String class.




PreviousNext

Related