Java OCA OCP Practice Question 2475

Question

Given:.

2. import java.text.*;  
3. public class Main {  
4.   public static void main(String[] args) throws Exception {  
5.     String s = "123.456xyz";  
6.     NumberFormat nf = NumberFormat.getInstance();  
7.     System.out.println(nf.parse(s));  
8.     nf.setMaximumFractionDigits(2);    
9.     System.out.println(nf.format(s));    
10.   }  //from   w  ww  . ja  va  2s .c o m
11. } 

Which are true? (Choose all that apply.).

  • A. Compilation fails.
  • B. The output will contain "123.45 "
  • C. The output will contain "123.456"
  • D. The output will contain "123.456xyz"
  • E. An exception will be thrown at runtime.


C and E are correct.

Note

The invocation of parse() will return 123.456.

The invocation of format() will throw an exception.




PreviousNext

Related