OCA Java SE 8 Building Blocks - OCA Mock Question Building Block 3








Question

Which of the following are true? (Choose all that apply)

     4: short myValue = 5; 
     5: int myValue2 = 1.2; 
     6: String myValue3 = "java2s.com"; 
     7: myValue.length(); 
     8: myValue2.length(); 
     9: myValue3.length(); 
     
  1. Line 4 generates a compiler error.
  2. Line 5 generates a compiler error.
  3. Line 6 generates a compiler error.
  4. Line 7 generates a compiler error.
  5. Line 8 generates a compiler error.
  6. Line 9 generates a compiler error.
  7. The code compiles as is.




Answer



B, D, E.

Note

A compiles because short is an integral type.

B generates a compiler error because int is an integral type, but 1.2 is a floating-point type.

C compiles because it is assigned a String.

D and E do not compile because short and int are primitives. Primitives do not allow methods to be called on them.

F compiles because length() is defined on String class.