Java OCA OCP Practice Question 3026

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. }  /*from  w  w w.  ja  v a  2 s  . c  om*/
 
11. import com.MyClass;  
12. public class Main {  
13.   public static void main(String[] args) {     
14.     MyClass.howdy();  
15.     System.out.print(MyClass.myConstant + " ");  
16.     System.out.print(myConstant + " ");  
17.     howdy();  
18.     System.out.print(mc.instVar + " ");  
19.     System.out.print(instVar + " ");  
20. } } 

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

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


D, E, F, and G are correct.

Note

Lines 16, 17, 18, and 19 are incorrect ways to access the elements of MyClass in package com.

A is incorrect because the code does not compile.

B and C are incorrect because those lines access the elements correctly.




PreviousNext

Related