40.7k views
2 votes
Consider the following statements about Java packages:

I. Packages don't provide a mechanism to partition all class names into more manageable chunks.
II. Packages provide a visibility control mechanism.
III. One of the important properties of a package is that all classes defined inside a package is accessible by code outside that package.
IV. The .class files for classes declared to be part of a package can be stored in multiple directories.
Which of them is correct?
(a) Only (I) above
(b) Only (II) above
(c) Only (III) above
(d) Only (IV) above
(e) All (I), (II), (III) and (IV) above are wrong.

User ULan
by
8.4k points

1 Answer

6 votes

Final answer:

In the context of Java packages, only statement II is correct as packages do provide a visibility control mechanism. Statements I, III, and IV are incorrect regarding partitioning class names, package accessibility by external code, and the storage of package .class files, respectively.

Step-by-step explanation:

The question asks about the properties of Java packages and which statements are correct regarding their attributes. Let's go through each statement:

  • Statement I is incorrect. Packages in Java do indeed provide a mechanism that helps partition classes into manageable chunks, helping to organize classes and interfaces.
  • Statement II is correct. Packages provide a visibility control mechanism through access modifiers such as public, protected, and default (package-private), which can be used to control whether classes in other packages can access certain classes and members.
  • Statement III is incorrect. Not all classes defined within a package are accessible by code outside that package. Whether they are accessible depends on the access modifiers applied to them.
  • Statement IV is incorrect. The .class files for classes declared to be part of a package must be stored in a directory structure that matches the package structure. It's not permissible to store .class files for the same package in multiple directories.

So, from the given options, (b) Only (II) above is the correct answer.

User Brodrigues
by
8.7k points