Java OCA OCP Practice Question 2865

Question

Given two files:

1. package com;  
2. public class MyClass {  
3.   public static void howdy() { System.out.print("howdy "); }  
4.   public static final int myConstant = 343;  
5.   public static final MyClass mc = new MyClass();  
6.   public int instVar = 42;  
7. }  /*  w  ww  .j a v  a  2 s .com*/
 
11. import static com.MyClass.*;   
12. public class Main {  
13.   public static void main(String[] args) {     
14.     System.out.print(myConstant + " ");  
15.     howdy();  
16.     System.out.print(mc.instVar + " ");  
17.     System.out.print(instVar + " ");  
18. } } 

What is the result? (Choose ALL that apply.)

  • A. 343 howdy 42 42
  • B. Compilation fails due to an error on line 11.
  • C. Compilation fails due to an error on line 14.
  • D. Compilation fails due to an error on line 15.
  • E. Compilation fails due to an error on line 16.
  • F. Compilation fails due to an error on line 17.


F   is correct.

Note

Line 17 is incorrect syntax to access instVar.

All of the remaining code is legal.

It's legal to use static imports to access static methods, constants (which are static and final), and static object references.




PreviousNext

Related