Page 178 - ComputerScience_Class_11
P. 178
• Right Shift (num >> 2):
° num = 32, in binary: 100000
° Shifting the bits 2 positions to the right: 001000, which is 8 in decimal.
Thus, the results are:
• Left Shift result: 256
• Right Shift result: 8
E. Assertion and reasoning questions.
The following questions consist of two statements – Assertion (A) and Reason (R). Answer these questions by selecting the
appropriate option given below:
a. Both A and R are true and R is the correct explanation of A.
b. Both A and R are true but R is not the correct explanation of A.
c. A is true but R is false.
d. A is false but R is true.
1. Assertion (A): The final keyword in Java ensures that a variable's value cannot be changed once it is assigned.
Reason (R): The final keyword must be used when declaring the variable and it requires an initial value to be assigned.
Ans. a. Both A and R are true and R is the correct explanation of A.
2. Assertion (A): The modulus operator (%) can only be used with integers.
Reason (R): The modulus operator is used to find the remainder of a division between two operands.
Ans. d. A is false but R is true.
3. Assertion (A): The ternary operator (? :) in Java is a shorthand for if-else statements.
Reason (R): The ternary operator works by checking a condition and returning one of two expressions based on whether the
condition is true or false.
Ans. a. Both A and R are true and R is the correct explanation of A.
F. Case study-based questions.
A housing society is developing a Java program to calculate the monthly electricity bill for each flat. The program stores the number
of units consumed as a variable, since the consumption changes every month. The cost per unit is fixed and declared using a final
variable to avoid accidental modification during execution. The total bill amount is calculated using arithmetic operators such as
multiplication and addition.
Relational operators are used to check whether the total units consumed exceed a certain limit to apply a surcharge. Logical operators
are used to determine whether both high consumption and peak-hour usage conditions are satisfied. The program uses shorthand
assignment operators to update the bill amount after adding fixed charges.
The final bill amount is displayed after evaluating all expressions correctly.
Based on the given case, answer the following questions:
1. The program is developed to calculate the ………………… electricity bill for each flat.
a. daily b. weekly
c. monthly d. yearly
2. Which keyword is used to declare the cost per unit as a fixed value in the program?
a. static b. final
c. const d. fixed
3. Which category of operators is used to calculate the total bill amount?
a. Relational operators b. Logical operators
c. Arithmetic operators d. Bitwise operators
4. Which operators are used to check whether both high consumption and peak-hour usage conditions are satisfied?
a. Arithmetic operators b. Relational operators
c. Shorthand operators d. Logical operators
Answers
1. c 2. b 3. c 4. d
176 Touchpad Computer Science (Ver. 3.0)-XI

