Java OCA OCP Practice Question 54

Question

Which one of the following statements is true about using packages to organize your code in?Java?

  • A. Every class is required to include a package declaration.
  • B. To create a new package, you need to add a package.def file to the directory.
  • C. Packages allow you to limit access to classes, methods, or data from classes outside the package.
  • D. It is not possible to restrict access to objects and methods within a package.


C.

Note

Classes may be defined without a package declaration and are placed in the default package, so Option A is incorrect.

Option B is a completely false statement as no such file is required in Java.

Option C is correct as it is one of the primary reasons for organizing your application into packages.

Option D is incorrect as package-private allows access to methods and variables to be limited to those classes within the same package.




PreviousNext

Related