
















































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A Java-focused maintainability certification practice exam emphasizing clean coding, object-oriented structure, refactoring, maintainability metrics, documentation, architecture evaluation, debugging, and lifecycle management. Ideal for Java developers pursuing CQSD credentials.
Typology: Exams
1 / 88
This page cannot be seen from the preview
Don't miss anything!

















































































Question 1. Which ISO/IEC 25010 characteristic directly measures how easily software can be modified to correct faults or adapt to new environments? A) Reliability B) Maintainability C) Performance Efficiency D) Security Answer: B Explanation: Maintainability is defined in ISO/IEC 25010 as the degree of effectiveness and efficiency with which a product can be modified. Question 2. In the context of business value, high maintainability primarily contributes to which of the following? A) Increased initial development cost B) Faster delivery of new features C) Higher memory consumption D) Reduced code readability Answer: B Explanation: Easier modification reduces time and cost for future changes, enabling faster delivery of new functionality. Question 3. Which quality attribute is most likely to suffer if maintainability is neglected? A) Portability B) Reliability
C) Accessibility D) Compatibility Answer: B Explanation: Poor maintainability often leads to bugs and regressions, lowering reliability. Question 4. Which type of software maintenance focuses on fixing defects discovered after release? A) Adaptive B) Perfective C) Corrective D) Preventive Answer: C Explanation: Corrective maintenance addresses faults and errors in the existing system. Question 5. Which metric is most appropriate for measuring the size of a unit (method) in Java? A) Cyclomatic Complexity B) Lines of Code (LOC) C) Coupling Between Objects (CBO) D) Depth of Inheritance Tree (DIT) Answer: B Explanation: LOC directly measures the size of a method. Question 6. Cyclomatic Complexity primarily assesses which characteristic of a method? A. Number of parameters
A. Inappropriate Intimacy B. Feature Envy C. Message Chain D. Divergent Change Answer: B Explanation: Feature Envy occurs when a method is more interested in another class’s data than its own. Question 10. Which refactoring extracts a fragment of code into a new, well-named private method? A. Move Method B. Extract Method C. Inline Method D. Replace Method with Method Object Answer: B Explanation: Extract Method creates a new method from a selected code fragment. Question 11. Before performing any refactoring, which safeguard is considered essential? A. Code obfuscation B. A comprehensive test suite C. Removing all comments D. Converting all variables to static Answer: B Explanation: Tests ensure behavior remains unchanged after refactoring.
Question 12. Replacing a long series of if-else statements with subclasses that override a method is an example of: A. Extract Class B. Replace Conditional with Polymorphism C. Decompose Conditional D. Introduce Parameter Object Answer: B Explanation: Polymorphism eliminates conditional logic by delegating to overridden methods. Question 13. Which refactoring pattern helps eliminate a long parameter list by grouping related parameters into a single object? A. Introduce Explaining Variable B. Replace Method with Method Object C. Introduce Parameter Object D. Move Field Answer: C Explanation: Parameter Object encapsulates multiple parameters into one class. Question 14. Which SOLID principle advises that a class should have only one reason to change? A. Open/Closed Principle B. Liskov Substitution Principle C. Single Responsibility Principle D. Dependency Inversion Principle Answer: C Explanation: SRP states that a class should have a single responsibility.
Question 18. In Java, which construct helps avoid resource leaks by automatically closing resources? A. try-catch-finally B. synchronized block C. try-with-resources D. static initializer Answer: C Explanation: try-with-resources ensures AutoCloseable resources are closed. Question 19. Which collection type provides O(1) average-time complexity for get and put operations? A. ArrayList B. LinkedList C. HashMap D. TreeSet Answer: C Explanation: HashMap offers constant-time average performance for key-based access. Question 20. When should you prefer StringBuilder over the + operator in a loop? A. When concatenating a fixed number of strings B. When building a string inside a loop C. When the string is immutable D. When the code runs on Java 8 or earlier Answer: B
Explanation: StringBuilder reduces the overhead of creating many intermediate String objects in loops. Question 21. Which code smell is indicated by a class that contains only a few methods and fields, providing little functionality? A. Lazy Class B. Large Class C. God Object D. Data Clump Answer: A Explanation: A Lazy Class does not justify its existence. Question 22. The “Shotgun Surgery” smell most directly impacts which maintainability metric? A. Cyclomatic Complexity B. Change Propagation C. Code Duplication D. Lines of Code Answer: B Explanation: Shotgun Surgery forces many small changes across modules, increasing change propagation cost. Question 23. Which refactoring replaces a group of related methods in a class with an interface that the class implements? A. Extract Interface B. Replace Inheritance with Delegation C. Move Method D. Inline Class
Answer: B Explanation: DCP directly measures code duplication. Question 27. Which refactoring helps to break a large method by moving its body into a new class that can be further decomposed? A. Extract Class B. Replace Method with Method Object C. Move Method D. Inline Method Answer: B Explanation: Method Object converts a long method into a class, enabling finer decomposition. Question 28. Which of the following is an example of “Inappropriate Intimacy” between two classes? A. One class uses another’s private fields via reflection B. Both classes implement the same interface C. One class extends the other D. Both classes are in the same package Answer: A Explanation: Accessing private internals breaks encapsulation, showing inappropriate intimacy. Question 29. Which design principle encourages creating many small, client-specific interfaces rather than one large interface? A. Interface Segregation Principle B. Single Responsibility Principle C. Open/Closed Principle
D. Dependency Inversion Principle Answer: A Explanation: ISP reduces the impact of changes on clients by providing only needed methods. Question 30. Which of the following best describes the “Feature Envy” smell? A. A class that knows too much about another class’s internals B. A method that uses many methods of another class C. A class that has too many responsibilities D. A method that contains a long chain of calls Answer: B Explanation: Feature Envy occurs when a method is more interested in another class’s data. Question 31. When using JUnit, which annotation indicates that a method should be executed before each test case? A. @After B. @BeforeAll C. @BeforeEach D. @Test Answer: C Explanation: @BeforeEach runs before each test method. Question 32. Which of the following statements about immutable classes in Java is FALSE? A. All fields must be final B. The class should be declared final
B. Number of unit tests C. Cyclomatic Complexity per method D. Number of packages Answer: A Explanation: Large Class increases LOC per class, indicating size bloat. Question 36. Which of the following is a benefit of using the @Override annotation in Java? A. It improves runtime performance B. It guarantees thread safety C. It helps the compiler detect mismatched method signatures D. It makes the method static Answer: C Explanation: @Override signals intent and lets the compiler check that a method truly overrides a superclass method. Question 37. Which code smell is indicated by a method that performs several unrelated tasks? A. Long Method B. Divergent Change C. God Method D. Feature Envy Answer: C Explanation: A “God Method” (often called Long Method) violates SRP by doing many things. Question 38. Which refactoring moves a method from a class that does not need it to a class that uses it more appropriately?
A. Move Method B. Extract Method C. Inline Method D. Replace Method with Method Object Answer: A Explanation: Move Method relocates behavior to a more suitable class. Question 39. In Java, which keyword is used to declare a constant that cannot be changed after initialization? A. const B. static C. final D. immutable Answer: C Explanation: The final keyword makes a variable immutable after assignment. Question 40. Which of the following is a recommended practice for naming boolean variables? A. Use prefixes like is, has, can B. Use single letters like b C. Use verbs in past tense D. Use all caps Answer: A Explanation: Prefixes convey the true/false nature clearly. Question 41. Which of the following best describes “Dead Code”? A. Code that is duplicated in multiple places
B. Many classes need to be changed for a single feature addition C. A method contains a large switch statement D. Two classes share identical code Answer: A Explanation: Divergent Change means a class has multiple reasons to change, violating SRP. Question 45. Which of the following is the most appropriate way to handle a checked exception that cannot be reasonably recovered from? A. Convert it to an unchecked exception and rethrow B. Swallow it silently C. Print stack trace and continue D. Return null Answer: A Explanation: Wrapping in a RuntimeException propagates the error while avoiding forced handling. Question 46. In a Maven project, which file typically contains the list of dependencies and build configuration? A. settings.xml B. pom.xml C. build.gradle D. README.md Answer: B Explanation: pom.xml is the core Maven descriptor. Question 47. Which of the following statements about “Extract Interface” refactoring is TRUE?
A. It removes all implementations of the original class B. It creates a new interface and updates clients to depend on it C. It merges two unrelated classes into one D. It converts static methods into instance methods Answer: B Explanation: Extract Interface defines a contract and encourages programming to an abstraction. Question 48. Which of the following is NOT a recommended practice for writing Javadoc comments? A. Document the purpose of the method, not its implementation details B. Include @param and @return tags for all parameters and return values C. Use HTML tags for formatting D. Document every line of code inside the method body Answer: D Explanation: Javadoc should describe the API, not internal line-by-line details. Question 49. Which of the following is a primary advantage of using composition over inheritance? A. Faster method calls B. Reduced coupling and better encapsulation C. Ability to override private methods D. Automatic serialization Answer: B Explanation: Composition favors “has-a” relationships, lowering tight coupling inherent in inheritance.
Question 53. Which of the following is a sign that a method may benefit from the “Introduce Explaining Variable” refactoring? A. The method contains a complex arithmetic expression B. The method has more than 100 lines C. The method calls three other methods in sequence D. The method returns void Answer: A Explanation: Introducing a temporary variable clarifies complex expressions. Question 54. Which of the following statements about unit testing is FALSE? A. Unit tests should be isolated from external systems B. Unit tests can serve as executable documentation C. Unit tests must cover 100% of the code base to be effective D. Unit tests help detect regressions after refactoring Answer: C Explanation: 100% coverage is impractical; quality matters more than sheer percentage. Question 55. Which of the following is the most appropriate way to handle a null argument in a public API method? A. Allow the null and let a NullPointerException occur later B. Throw an IllegalArgumentException with a clear message C. Convert the null to an empty string silently D. Ignore the argument Answer: B
Explanation: Validating arguments and throwing a descriptive exception improves API robustness. Question 56. Which design pattern is most suitable for creating families of related objects without specifying their concrete classes? A. Builder B. Factory Method C. Abstract Factory D. Singleton Answer: C Explanation: Abstract Factory provides an interface for creating related objects. Question 57. Which of the following is a direct consequence of high code duplication? A. Decreased cyclomatic complexity B. Increased maintenance effort C. Improved test coverage D. Reduced binary size Answer: B Explanation: Duplicate code means changes must be made in multiple places, raising effort. Question 58. Which of the following refactorings is most appropriate when a class has too many responsibilities? A. Extract Class B. Inline Class C. Move Method D. Replace Inheritance with Delegation