Java Modules MCQ Questions and Answers
Q. What is a Java Module?
A. A self-contained package that encapsulates a set of related classes and interfacesB. A way to organize and structure Java code into separate functional units
C. A collection of Java files that can be compiled and executed independently
D. All of the above
Q. What is the main benefit of using Java Modules?
A. Improved performanceB. Better code organization and maintainability
C. Enhanced security
D. All of the above
Q. How do you declare a Java Module?
A. Using the module keyword followed by the module nameB. By creating a new file with a .module extension
C. Using the package keyword followed by the module name
D. None of the above
Q. What is the difference between a package and a module in Java?
A. A package is a collection of related classes, while a module is a collection of related packages.B. A package is a way to organize classes, while a module is a way to organize packages.
C. A package is a physical grouping, while a module is a logical grouping.
D. All of the above
Q. How do you export a package from a module?
A. Use the exports keyword followed by the package nameB. Use the open keyword followed by the package name
C. Use the provides keyword followed by the package name
D. Use the requires keyword followed by the package name
Q. What is the purpose of the requires directive in a module?
A. To specify the dependencies of a moduleB. To import classes from another module
C. To export packages from the current module
D. To open a package to all modules
Q. What is the difference between requires transitive and requires static in module declaration?
A. requires transitive includes the dependencies of the required module, while requires static does not.B. requires transitive is used for runtime dependencies, while requires static is used for compile-time dependencies.
C. requires transitive is used for optional dependencies, while requires static is used for mandatory dependencies.
D. requires transitive includes all modules in the module path, while requires static includes only the specified module.
Q. How do you provide services in a Java Module?
A. Use the provides keyword followed by the service interface and implementation classB. Implement the service interface and export the implementation class
C. Use the services keyword followed by a list of service provider classes
D. Use the uses keyword followed by the service interface
Q. What is the purpose of the open keyword in a module declaration?
A. To make a package accessible to all modulesB. To allow classes from other modules to access the package
C. To make the package public and allow external access
D. All of the above
Q. How do you use classes from another module in your code?
A. Import the class using the import statementB. Require the module using the requires directive
C. Export the class from the other module
D. Open the package containing the class