Java OCA OCP Practice Question 2986

Question

Given two files:

1. package com;  
2. public class Shape {  
3.   public static void howdy() { System.out.print("howdy "); }  
4.   public static final Shape ex = new Shape();  
5.   public int instVar = 42;  
6.   public enum avout {A, B};  
7. }  //  ww  w.  j a  va2s. co  m
 
1. // insert code here  
...  
6. public class Main {  
7.   public static void main(String[] args) {     
8.     Shape.howdy();  
9.     System.out.print(Shape.avout.A + " ");   
10.     howdy();  
11.     System.out.print(ex.instVar + " ");  
12. } } 

Which are the minimum line(s) of code to add at "insert code here" for the files to compile? (Choose all that apply.)

  • A. import static com.*;
  • B. import com.Shape;
  • C. import com.Shape.*;
  • D. import static com.Shape;
  • E. import static com.Shape.*;
  • F. Even with correct imports, the code will not compile due to other errors.


B and E

Note

B and E are the import statements that correctly allow access to the elements in Shape.

A, C, and D are incorrect.

These import statements will not allow access to the elements of Shape invoked in Main.

F is incorrect because with the correct import statements in place, the code will compile.




PreviousNext

Related