Java OCA OCP Practice Question 2347

Question

Given:

class MyClass { 
   //..code 
} 

Which of the following options will compile?

a  package java.oca.associate; 
   class Main { //from   w  w  w .  j  av  a2s .c  o  m
       MyClass eJava = new MyClass(); 
   } 

b  package java.oca; 
   import MyClass; 
   class Main { 
       MyClass eJava; 
   } 

c  package java.oca.*; 
   import java.default.*; 
   class Main { 
       MyClass eJava; 
   } 


  package java.oca.associate; 
  import default.*; 
  class Main { 
      default.MyClass eJava; 
   } 

  None of the above 


e

Note

A class that isn't defined in a package gets implicitly defined in Java's default package.

But such classes can't be accessed by classes or interfaces, which are explicitly defined in a package.

Option a is incorrect.

The MyClass class isn't defined in a package, so it can't be accessed by the Main class, which is defined in the java.oca.associate package.

Options b, c, and d won't compile.

Option b uses invalid syntax in the import statement.

Options c and d try to import classes from nonexistent packages-java.

default and default.




PreviousNext

Related