- A10
- B12
- C20
- D11
Time Taken:
Correct Answer:
Wrong Answer:
Percentage: %
Let's break down the two string method operations in Java for the string "MISSISSIPPI":
"MISSISSIPPI".indexOf('S')The indexOf('S') method returns the index of the first occurrence of the character 'S' in the string "MISSISSIPPI".
The string "MISSISSIPPI" has the following indices:
M I S S I S S I P P I 0 1 2 3 4 5 6 7 8 9 10
So, "MISSISSIPPI".indexOf('S') returns 2.
"MISSISSIPPI".lastIndexOf('I')The lastIndexOf('I') method returns the index of the last occurrence of the character 'I' in the string "MISSISSIPPI".
So, "MISSISSIPPI".lastIndexOf('I') returns 10.
Now, adding these two results together:
indexOf('S') + lastIndexOf('I') = 2 + 10 = 12
So, the correct answer is:
12
The break statement is used to exit the current loop.
Here is an example in Java to demonstrate its usage:
public class BreakStatementExample { public static void main(String[] args) { // Loop from 1 to 5 for (int i = 1; i <= 5; i++) { if (i == 3) { break; // Exit the loop when i is 3 } System.out.println("Iteration: " + i); } System.out.println("Loop exited."); } }
Output:
Iteration: 1 Iteration: 2 Loop exited.
In this example, the break statement exits the loop when i equals 3, so the loop stops executing and the program continues with the next statement after the loop.
Explanation:
In Call by Value, the values of the actual parameters are copied to the formal parameters. Any changes made to the formal parameters do not affect the actual parameters.
POS
Reason — The substring() method returns a substring beginning from the startindex and extending to the character at endIndex - 1. Since a string index begins at 0, the character at index 3 is 'P' and the character at index 5 (6-1 = 5) is 'S'. Thus, "POS" is extracted.
Pure method
Reason — A method which does not modify the value of variables is termed as a pure method.
Wrapper
Reason — Wrapper class is used to convert a primitive data type to its corresponding object.
Each double in Java occupies 8 bytes, and the array contains 4 elements.
Total memory occupied = 8 bytes × 4 = 32 bytes
Correct answer: (d) 32
array is not a user-defined data type; it is a derived data type.
double is a primitive data type (not user-defined).
class is a user-defined data type.
boolean is a primitive data type.
✅ Correct Answer: (b) 1 and 3 (Array and Class)
(a) public
Explanation: A post office is accessible to everyone, similar to public access specifier.