Page 99 - CA_Blue( J )_Class10
P. 99
What type of comment is Jake using, and what is its purpose?
a. Single-line comment; It briefly explains a specific line of code.
b. Multi-line comment; It comments out multiple lines of code.
c. Javadoc comment; It provides documentation for the method, detailing its purpose and parameters.
d. Inline comment; It explains a specific part of a line of code.
2. Max writes a method to calculate the total price of an order. He initializes a variable to hold the total price.
class Order {
public double calculateTotalPrice(double[] prices)
{
double totalPrice = 0.0; // Initialize the total price
for (double price : prices)
{
totalPrice += price;
}
return totalPrice;
}
}
What is the purpose of initializing totalPrice to 0.0?
a. To avoid a compilation error.
b. To set a starting value that can be used in the calculation.
c. To reserve memory for the variable.
d. To make the code easier to read.
Previous Years' Questions
1. The Scanner class method used to accept words with space: [2023]
a. next() b. nextLine()
c. Next() d. nextString()
Ans. b
2. Name the type of error in the statement givn below: [2022]
double x;y;z;
a. Logical error b. Syntax error
c. Runtime error d. No error
Ans. b
3. State whether the statement is True or False:
Multi.line comments in Java start with /* and end with */. [2022]
a. True b. False
Ans. a
4. Choose the odd one: [2022]
a. nextlnt() b. nextDouble()
c. nextString d. next()
Ans. c
5. Give the output of the following code:
String p = "20", q = "19";
int a = Integer.parseInt(p);
int b = Integer.valueOf(q);
System.out.println(a + "" + b); [2019]
Ans. 2019
97
Input in Java 97

