Page 317 - CA_Blue( J )_Class9
P. 317
(xviii) How many times the loop will execute?
int i=45;
for(;i>=5;i=i-5)
{
System.out.println(i);
}
(a) 8 (b) 4
(c) 9 (d) 0
Ans. (c) 9
(xix) Assertion(A): Java Application, cannot run independently on a computer.
Reason(R): The features of Java are simple, robust, secure, platform-independent, object-oriented, etc.
(a) Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of Assertion (A).
(b) Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation of Assertion (A).
(c) Assertion (A) is true and Reason (R) is false.
(d) Assertion (A) is false and Reason (R) is true.
Ans. (c) Assertion (A) is true and Reason (R) is false.
(xx) To protect Data Privacy, we need
(a) A good Firewall (b) A good Antivirus
(c) Both a and b (d) None of these
Ans. (c) Both a and b
Question 2. [20]
(i) What are Literals in Java? Also explain the String Literals. [2]
Ans. Literals in Java are values that are assigned to a variable. They are used by programmers and can be of any data type. Literals
are also called constants.
For example, int a=20; (Here, 20 is a literal).
String literals are any sequence of characters with a double quote. For example, "India", "Computer Application of class 10".
(ii) Write the difference between declaration and initialisation. [2]
Ans. Declaration is to declare the type of the variable, whereas Initialization is the assignment of a value to a variable at the time
of declaration.
Example: int a; // simple declaration
Whereas, a = 10; // simple assignment
(iii) Write a program in Java to calculate the value of c (c = a++ * ++b) and display the value of c. [2]
Ans. class unary_operator
{
public static void main(int a, int b)
{
int c;
c = a++ * ++b;
System.out.println("Result "+c);
}
}
(iv) Give the output of the following expression: [2]
y += x++ * 2 / x++ + y; if x=20, y=15;
Ans. y = y + (x++ * 2 / x++ + y)
= 15 + (20 * 2 / 21 + 15)
= 15 + (40 / 21 + 15)
= 15 + (1 + 15)
= 15 + 16
= 31
Model Test Paper 315

