Java OCA OCP Practice Question 1411

Question

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

public class Main{ 
   public static void main (String args [] ){ 
      StringBuilder sb = new StringBuilder ("12345678"); 
      sb .setLength (5); 
      sb .setLength (10); 
      System.out.println (sb .length ()); 
    } 
} 

Select 1 option

  • A. It will print 5.
  • B. It will print 10.
  • C. It will print 8.
  • D. Compilation error.
  • E. None of the above.


Correct Option is  : B

Note

If you do System.out.println (sb); it will indeed print 12345 but the length will be 10.




PreviousNext

Related