Java OCA OCP Practice Question 2323

Question

Assuming that all of the following classes are defined in separate source code files, select the incorrect statements.

package mypkg; //from www  .java  2s. co  m
public class Sun { 
    public Sun() {} 
} 

package stars; 
public class Sun { 
    public Sun() {} 
} 

package skyies; 
import stars.Sun;     // line1 
import mypkg.Sun;     // line2 
class Sky { 
    Sun sun = new Sun(); // line 3 
} 
  • a Code compilation fails at line 1.
  • b Code compilation fails at line 2.
  • c Code compilation fails at line 3.
  • d The code compiles successfully and class Sky creates an object of class Sun from the stars package.
  • e The code compiles successfully and class Sky creates an object of class Sun from the mypkg package.


b

Note

Class Sky fails with the following error message:

Sky.java:3: error: stars.Sun is already defined in a single-type import 
import mypkg.Sun; 
^ 
1 error 



PreviousNext

Related