Mastering Java Module System & Encapsulation
Test your understanding of Java's module system and encapsulation principles.
Questions in this quiz
12 questions on Mastering Java Module System & Encapsulation. Work through them here, then start the quiz to answer them and see your score.
1.What is the primary purpose of the Java Module System introduced in Java 9?
- ATo provide a new syntax for lambda expressions
- BTo improve performance of Java applications
- CTo encapsulate packages and manage dependencies
- DTo replace the Java Virtual Machine
2.In a module descriptor file (module-info.java), which keyword is used to specify dependencies on other modules?
- Aprovides
- Bexports
- Crequires
- Duses
3.Which of the following is NOT a benefit of using the Java Module System?
- AReduced memory usage
- BImproved security
- CBetter encapsulation
- DSimplified class loading
4.How does the 'exports' directive in a module descriptor affect encapsulation?
- AIt hides all packages from other modules
- BIt allows specific packages to be accessible to other modules
- CIt allows all packages to be accessible to other modules
- DIt makes all classes in the module public
5.Which of the following statements about encapsulation in Java is true?
- AEncapsulation is achieved by restricting access to class members
- BEncapsulation is achieved using the 'public' keyword
- CEncapsulation is not supported in Java
- DEncapsulation allows direct access to class fields
6.What is the role of the 'provides' directive in a module descriptor?
- ATo declare a module's dependencies
- BTo import a package
- CTo export a package
- DTo specify an implementation for a service interface
7.Which access modifier would you use to ensure a class member is only accessible within its own package?
- Aprivate
- Bdefault (no modifier)
- Cprotected
- Dpublic
8.How does the 'uses' directive in a module descriptor contribute to the module system?
- AIt declares a module's dependencies
- BIt specifies a service that the module consumes
- CIt exports a package
- DIt imports a package
9.What is the effect of marking a class as 'final' in Java?
- AThe class cannot have any methods
- BThe class cannot be instantiated
- CThe class cannot be subclassed
- DThe class cannot be accessed outside its package
10.Which of the following is a correct statement about the 'open' module directive?
- AIt opens a specific package for reflection
- BIt exports all packages in the module
- CIt requires another module
- DIt allows all packages in the module to be accessible at runtime
11.What is the primary advantage of encapsulation in object-oriented programming?
- AIt enables multiple inheritance
- BIt allows for code reuse
- CIt hides the internal state and requires all interaction to be performed through an object's methods
- DIt increases the performance of the application
12.In the context of the Java Module System, what does 'transitive' mean when used with the 'requires' directive?
- AIt makes a module's packages accessible at runtime
- BIt allows a module to automatically export its packages
- CIt prevents a module from being accessed by other modules
- DIt allows a module's dependencies to be automatically included in the module's consumers