Java OCA OCP Practice Question 2788

Question

Given two files:.

1. package com.mypkg;  
2. import com.mypkg2.*;  
3. public class Main {  
4.   public static void main(String[] args) {  
5.     MyClass u = new MyClass();  
6.     u.do1();  
7.     u.do2();  
8.     u.do3();  
9. } } 

and the correctly compiled and located:.

1. package com.mypkg2;  
2. class MyClass {  
3.   void do1() { System.out.print("do1 "); }  
4.   protected void do2() { System.out.print("do2 "); }  
5.   public void do3() { System.out.print("do3 "); }  
6. } 

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

  • A. do1 do2 do3
  • B. "do1 ", followed by an exception
  • C. Compilation fails due to an error on line 5 of Main.
  • D. Compilation fails due to an error on line 6 of Main.
  • E. Compilation fails due to an error on line 7 of Main.
  • F. Compilation fails due to an error on line 8 of Main.


C, D, E, and F are correct.

Note

class MyClass is not public so it CANNOT be accessed from a different package.




PreviousNext

Related