Java OCA OCP Practice Question 153

Question

Given:

public class Main { 
  public static void main(String[] args) { 
    int i1 = 1_000;      // line A 
    int i2 = 10_00;      // line B 
    int i3 = _10_000;    // line C 
    int i4 = 0b101010;   // line D 
    int i5 = 0B10_1010;  // line E 
    int i6 = 0x2_a;      // line F 
  } /*from   www. jav  a  2  s  .co  m*/
} 

Which lines WILL NOT compile?

Choose all that apply.

  • A. Line A
  • B. Line B
  • C. Line C
  • D. Line D
  • E. Line E
  • F. Line F


C is correct; line C will NOT compile.

Note

As of Java 7, underscores can be included in numeric literals, but not at the beginning or the end.

A, B, D, E, and G are incorrect.

A and B are legal numeric literals.

D and E are examples of valid binary literals, which are also new to Java 7.

G is a valid hexadecimal literal that uses an underscore.




PreviousNext

Related