Java OCA OCP Practice Question 697

Question

What will be result of attempting to compile this class?

import java.util.*; 
package test; 
public class Main{ 
    public MyClass oc = new MyClass (); 
} 
class MyClass{ 
    int value; 
} 

Select 1 option

  • A. The class will fail to compile, since the class MyClass is used before it is defined.
  • B. There is no problem with the code.
  • C. The class will fail to compile, since the class MyClass must be defined in a file called MyClass.java
  • D. The class will fail to compile .
  • E. None of the above.


Correct Option is  : D

Note

The order is:

  • package statement.
  • import statements
  • class/ interface definitions.



PreviousNext

Related