Java OCA OCP Practice Question 2576

Question

Which of the following statements can be inserted to make Main compile?

package my.sports; 
public class Football { 
   public static final int TEAM_SIZE = 11; 
} 

package my.apps; 
// INSERT CODE HERE 

public class Main { 

   public int getTeamSize() { return TEAM_SIZE; } 
} 
  • A. import my.sports.Football;
  • B. import static my.sports.*;
  • C. import static my.sports.Football;
  • D. import static my.sports.Football.*;
  • E. static import my.sports.*;
  • F. static import my.sports.Football;
  • G. static import my.sports.Football.*;


D.

Note

Main is trying to refer to a static variable in another class.

It needs a static import to do so.

The correct syntax is import static and not static import.

B is incorrect because * does not import classes in a package.

C is incorrect because it does not refer to a static member.




PreviousNext

Related