A financial application calculates compound interest. During a code review, the following line is flagged: `double total = principal * Math.pow(1 + rate, time);`. The variables `principal`, `rate`, and `time` are all of type `double`. Which statement accurately describes the use of the `Math` class in this context?
Q2
A developer needs to create a utility method that calculates the area of a circle. The method should be accessible without creating an instance of the class it resides in. The method signature is intended to be: `public ___ double calculateArea(double radius)`. Which keyword must be placed in the blank to meet this requirement?
Q3
A developer is writing a program to simulate a dice roll, which should produce a random integer between 1 and 6 (inclusive). They have written the following code snippet: ```java import java.util.Random; // ... inside a method Random rand = new Random(); int result = // ... code to generate number ... ``` Which line of code correctly generates the required random number?
Q4Multiple answers
A class `DataProcessor` is designed with multiple methods to handle different data types. Examine the following method signatures within the class: 1. `public void process(int data)` 2. `public void process(int data, boolean flag)` 3. `public int process(double data)` 4. `public void process(int value)` Which two method signatures will cause a compilation error due to invalid method overloading? (Select TWO)
Q5
True or False: A single `.java` source file can contain multiple `public` class declarations.
Q6
What is the output of the following code snippet? ```java int x = 5; int y = 2; double z = x / y; System.out.println(z); ```
Q7
A developer is implementing a system that categorizes user levels. They need to write a method `getUserCategory` that takes an integer `level` and returns a `String`. The logic is as follows: - If `level` is 1, return "Beginner". - If `level` is 2, return "Intermediate". - If `level` is 3, return "Advanced". - For any other level, return "Expert". Which control flow statement is most suitable and readable for implementing this logic?
Q8
A program processes a list of task IDs stored in an `ArrayList`. During processing, if a task ID of -1 is encountered, the program should immediately stop processing and exit the loop. Which code snippet correctly implements this requirement? ```java ArrayList taskIds = new ArrayList (); // ... taskIds is populated ... for (int id : taskIds) { if (id == -1) { // What goes here? } System.out.println("Processing task: " + id); } ```
Q9Multiple answers
A new developer is working with arrays and `ArrayLists` for the first time. They need to understand the fundamental differences between the two. Which of the following statements are true regarding arrays and `ArrayLists` in Java? (Select TWO)
Q10
**Case Study:** A small startup is developing a `UserProfile` class for its new social media application. The requirements state that every user profile must be created with a unique username and an email address, which cannot be changed after creation. A user's display name is also required at creation but can be modified later. Finally, a user's biography is optional and can be set or updated at any time. The lead developer has mandated the following design principles: - All instance variables (fields) must be `private` to ensure encapsulation. - The class must provide constructors to enforce the creation rules. - Methods should be provided to access and modify data where allowed. Which class implementation best meets all the specified requirements?