MS MockTest Group1 Gr10
MS MockTest Group1 Gr10
2023-24
Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins
Question 1(i)
What will be the output of the following code?
int size = 2;
if (size < 0)
System.out.println("Small");
else if (size == 0)
System.out.println("Medium");
else
System.out.println("Large");
a) Small
b) Large
c) Medium
d) Runtime error
Answer
Large
Reason — Since size > 0, hence the conditions of if and else if are false. Thus, the
else block will be executed and "Large" will be printed on the screen.
Question 1(ii)
Which of the following statements involves a fall through?
a) if-else
b) for loop
c) if-else-if
d) switch
Answer
switch
Mock Test
2023-24
Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins
Reason — Omitting break statement leads to program execution continuing into the
next case and onwards till a break statement is encountered or end of switch is
reached.
Question 1(iii)
Which of the following statement is true for logical errors?
Answer
All of the above
Reason — The compiler does not detect logical errors and there is no indication of
error when the program is executed. The program may produce correct results for
some input data and wrong results for other input data.
Question 1(iv)
Object oriented programming mainly uses
Answer
bottom up approach
Reason — Object Oriented Programming follows bottom-up approach because in
OOP we first identify the smallest parts of the program i.e. the objects. We then
combine these objects to develop the complete program.
Question 1(v)
Mock Test
2023-24
Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins
In which technique are the values of actual parameters copied to the formal
parameters?
a) Call by reference
b) Call by value
c) Call by argument
d) Call by method
Answer
Call by value
Reason — In call by value, the actual parameters are copied to formal parameters.
Any changes to formal parameters are not reflected onto the actual parameters.
Question 1(vi)
Which package would you import for the Scanner class?
a) java.util.*;
b) java.awt.*;
c) java.io.*;
d) java.lang.*;
Answer
java.util.*;
Reason — Scanner class is a part of java.util package.
Question 1(vii)
Give the output of Math.abs(x); when x = -9.99.
a) -9.99
b) 9.99
c) 0.99
d) None of these
Answer
9.99
Mock Test
2023-24
Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins
Reason — Math.abs() returns the absolute value of its argument. Its return type is
same as the type of its argument. Thus, Math.abs(-9.99) returns 9.99.
Question 1(viii)
A/An ............... is an abstract description of a set of objects.
a) abstraction
b) encapsulation
c) polymorphism
d) class
Answer
class
Reason — A class is an abstract description of a set of objects.
Question 1(ix)
This variable can be accessed by calling with the class name.
a) Instance
b) Local
c) Class
d) None of these
Answer
Class
Reason — Class variable can be accessed by calling with the class name.
Question 1(x)
The main objective of passing arguments to functions is
a) message passing
b) parameter passing
c) variable passing
d) argument passing
Mock Test
2023-24
Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins
Answer
message passing
Reason — The main objective of passing arguments to functions is message
passing.
Question 1(xi)
If int arr [] = {3, 5, 7, 9}; what is the value of arr.length?
a) 3
b) 5
c) 4
d) Cannot be determined
Answer
4
Reason — length property stores the number of elements in an array. Thus, the
value of arr.length is 4 as there are 4 elements in the array.
Question 1(xii)
A binary search
Answer
can be used with sorted arrays only.
Reason — A binary search can be used with sorted arrays only.
Question 1(xiii)
Corresponding wrapper class of float data type is
a) FLOAT
Mock Test
2023-24
Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins
b) float
c) Float
d) Floating
Answer
Float
Reason — Corresponding wrapper class of float data type is Float.
Question 1(xiv)
What will be the output of the following code?
System.out.println("Lucknow".substring (0, 4));
a) Lucknow
b) Luckn
c) Luck
d) luck
Answer
Luck
Reason — The substring() method returns a substring beginning from the
startindex and extending to the character at index endIndex - 1. Since a string index
begins at 0, the character at startindex (0) is 'L' and the character at the endIndex
(4-1 = 3) is 'k'. Thus, "Luck" is extracted and printed on the screen.
Question 1(xv)
This access specifier is the most open access level.
a) Public
b) Protected
c) Private
d) Default
Answer
Public
Mock Test
2023-24
Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins
Question 1(xvi)
The method to determine whether the specified char value is in uppercase or not.
a) toUpperCase(char)
b) toLowerCase(char)
c) isLowerCase(char)
d) isUpperCase(char)
Answer
isUpperCase(char)
Reason — isUpperCase() is used to check if the character given as its argument is
in upper case or not. It returns true if the argument is in uppercase, else returns
false.
Question 1(xvii)
Assertion (A) Method should be called explicitly either with object reference or
class reference.
Reason (R) Method can be any user defined name.
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.
Answer
Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct
explanation of Assertion (A).
Reason — Assertion (A) is true as a method should be called explicitly either with
object reference or class reference. Reason (R) is also true as a method can be
any user defined name, except a keyword. Reason (R) is not the correct
explanation of Assertion (A).
Mock Test
2023-24
Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins
Question 1(xviii)
Read the following text and choose the correct answer:
Public access specifier allows a class to expose its member variables and member
functions to other functions and objects. Any public member can be accessed from
outside the class.
Which of these access specifier must be used for class so that it can be inherited
by another subclass?
a) public
b) private
c) protected
d) none of the mentioned
Answer
public
Reason — According to the given context, public access specifier can be used for
class so that it can be inherited by another subclass.
Question 1(xix)
Assertion (A) The return statement causes program control to transfer back to the
caller of the method.
Reason (R) The return statement immediately terminates the method in which it is
executed.
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
Answer
Both Assertion (A) and Reason (R) are true and Reason (R) is a correct
explanation of Assertion (A).
Mock Test
2023-24
Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins
Reason — Assertion (A) is true as the return statement causes program control to
transfer back to the caller of the method. Reason (R) is also true as the return
statement immediately terminates the method in which it is executed and the
control transfers back to the caller method. Thus, Reason (R) correctly explains
Assertion (A).
Question 1(xx)
Correct statement to declare an integer array of 10 elements.
Answer
int[ ] arr = new int[10];
Reason — The correct syntax to declare an array is as follows:
datatype[ ] array_name = new datatype[size];
The statement int[ ] arr = new int[10]; follows the correct syntax of array declaration.
Question 2(i)
Write the values of c and d after execution of following code.
Mock Test
2023-24
Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins
int a = 1;
int b = 2;
int c;
int d;
c = ++b;
d = a++;
c++;
Answer
After the execution of the code, c = 4 and d = 1.
Explanation
Statement Remarks
c = ++b; Prefix operator first increments and then uses the value. Thus, c = 3, b = 3
d = a++; Postfix operator first uses and then increments the value. Thus, d = 1, a = 2
c=c+1
c++; =3+1
=4
Question 2(ii)
Observe the following code and write how many times will the loop execute?
a = 5;
b = 2;
while(b != 0)
{
r = a % b;
a = b;
b = r;
}
System.out.println(" " + a);
Answer
The loop will execute 2 times.
Explanation
Mock Test
2023-24
Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins
Iteration r a b Remark
5 2 Initial values
1 1 2 1 r=5%2=1
r=2%1=0
2 0 1 0
Loop terminates as b = 0
Question 2(iii)
Write the values that will be assigned to x, y and t after executing the following code.
String s1, s2, x, y;
int t;
s1 = "classxii";
s2 = "cbseboard";
x = s1.substring(5, 8);
y = s2.concat(s1);
t = y.length();
System.out.println("x=" + x);
System.out.println("y=" + y);
System.out.println("t=" + t);
Answer
Output
x=xii
y=cbseboardclassxii
t=17
Explanation
The substring() method returns a substring beginning from the startindex and extending to the character at
index endIndex - 1. Here, startindex is 5 and end index is 7 (8 - 1). Since the string starts from index 0, the
extracted substring is "xii". Thus x = xii.
The concat() method adds one string (s1) at the end of another string (s2). Thus, "classxii" is added to the end
of "cbseboard". Hence, y = "cbseboardclassxii.
The length() method returns the total number of characters in a string. Thus, t = 17.
Question 2(iv)
Write the values that will be stored in variables num and sum after execution of the following code.
int sum = 0, num = -2;
Mock Test
2023-24
Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins
do
{
sum = sum + num;
num++;
} while (num < 1);
Answer
After the execution of the given code, num = 1 and sum = -3
Explanation
0 -2 Initial values
1 -2 -1 sum = 0 + (-2) = -2
2 -3 0 sum = -2 + (-1) = -3
sum = -3 + 0 = -3
3 -3 1
Loop terminates
Question 2(v)
The following code has some error(s). Rewrite the correct code and underlining all the corrections made.
integer counter = 0;
i = 10; num;
for (num = i; num >= 1; num--);
{
If i % num = 0
{
counter = counter + 1;
}
}
Answer
The correct code is as follows:
int counter = 0; //Correction 1
int i = 10, num; //Correction 2
for (num = i; num >= 1; num--) //Correction 3
Mock Test
2023-24
Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins
{
if( i % num == 0) //Correction 4
{
counter = counter + 1;
}
}
Explanation
variable declaration cannot be done without a data type. The syntax for
Correction
i = 10; num; variable declaration is datatype variablename = value/expression;.
2
Multiple variables should be separated by comma not semicolon.
for (num = i; If a semicolon is written at the end of the for loop, the block of the loop
Correction
num >= 1; num- will not be executed. Thus, no semicolon should be written after for
3
-); loop.
Question 2(vi)
Rewrite the following program segment using while instead of for loop.
int f = 1, i;
for(i = 1; i <= 5 ; i++)
{
f *= i;
System.out.println(f);
}
Answer
int f = 1; i = 1;
while(i <= 5) {
f *= i;
System.out.println(f);
Mock Test
2023-24
Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins
i++;
}
Question 2(vii)
State the method that
(a) converts a string to a primitive float data type.
(b) determines if the specified character is an uppercase character.
Answer
(a) Float.parseFloat()
(b) Character.isUpperCase()
Question 2(viii)
Write the Java statement for the following mathematical expression:
a=0.02−3y3x+ya=x+y0.02−3y3
Answer
a = (0.02 - 3 * Math.pow(y, 3)) / (x + y);
Question 2(ix)
Give the output of the following expression, when a = 6.
a += ++a + a++ + a-- + a-- + --a + ++a
Answer
The output will be 46.
Explanation
a += ++a + a++ + a-- + a-- + --a + ++a [a = 6]
a = a + (++a + a++ + a-- + a-- + --a + ++a) [a = 6]
a = 6 + (7 + a++ + a-- + a-- + --a + ++a) [a = 7]
a = 6 + (7 + 7 + a-- + a-- + --a + ++a) [a = 8]
a = 6 + (7 + 7 + 8 + a-- + --a + ++a) [a = 7]
a = 6 + (7 + 7 + 8 + 7 + --a + ++a) [a = 6]
a = 6 + (7 + 7 + 8 + 7 + 5 + ++a) [a = 5]
a = 6 + (7 + 7 + 8 + 7 + 5 + 6) [a = 6]
a = 6 + 40
a = 46
Question 2(x)
Predict the output of the following.
(a) Math.pow(2.5, 2) + Math.ceil(5)
(b) Math.round(2.9) + Math.log(1)
Answer
Mock Test
2023-24
Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins
(a) 11.25
(b) 3.0
Explanation
(a) Math.pow(x, y) method returns the value of x raised to the power of y. Math.ceil() method returns the
smallest double value that is greater than or equal to the argument and is equal to a mathematical integer.
Thus, the given expression is evaluated as follows:
Math.pow(2.5, 2) + Math.ceil(5)
⇒ 6.25 + 5.0
⇒ 11.25
(b) Math.round() method rounds off its argument to the nearest mathematical integer and returns its value as an
int or long type. Math.log() method returns the natural logarithm of its argument. Thus, the given expression is
evaluated as follows:
Math.round(2.9) + Math.log(1)
⇒ 3 + 0.0
⇒ 3.0
Question 3 [15]
Member methods:
ShowRoom() — default constructor to initialize data members
Mock Test
2023-24
Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins
void display() — To display customer name, mobile number, amount to be paid after discount.
Write a main method to create an object of the class and call the above member methods.
Answer
import java.util.Scanner;
public ShowRoom()
{
name = "";
mobno = 0;
cost = 0.0;
dis = 0.0;
amount = 0.0;
}
Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins
Question 4 [15]
Define a class to accept a String and print the number of digits, alphabets and special characters in the string.
Example:
S = "KAPILDEV@83"
Output:
Number of digits – 2
Number of Alphabets – 8
Number of Special characters – 1
import java.util.Scanner;
Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins
System.out.println("Enter a string:");
String str = in.nextLine();
int ac = 0;
int sc = 0;
int dc = 0;
char ch;
}
}
Question 5 [15]
Define a class to accept 10 characters from a user. Using bubble sort technique arrange them in ascending
order. Display the sorted array and original array.
import java.util.Scanner;
System.out.println("Original Array");
for (int i = 0; i < ch.length; i++) {
Mock Test
2023-24
Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins
//Bubble Sort
for (int i = 0; i < ch.length - 1; i++) {
for (int j = 0; j < ch.length - 1 - i; j++) {
if (ch[j] > (ch[j + 1])) {
char t = ch[j];
ch[j] = ch[j + 1];
ch[j + 1] = t;
}
}
}
System.out.println("\nSorted Array");
for (int i = 0; i < ch.length; i++) {
System.out.print(ch[i] + " ");
}
}
}
Question 6 [15]
1 1 1 1
2 2 2 2
3 3 3 3
4 4 4 4
5 5 5 5
void print(int n) - To check whether the number is a lead number. A lead number is the one whose sum of even
digits are equal to sum of odd digits.
e.g. 3669
odd digits sum = 3 + 9 = 12
even digits sum = 6 + 6 = 12
3669 is a lead number.
import java.util.Scanner;
Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins
if(evenSum == oddSum)
System.out.println("Lead number");
else
System.out.println("Not a lead number");
}
System.out.println("Pattern: ");
obj.print();
Question 7 [15]
A tech number has even number of digits. If the number is split in two equal halves, then the square of sum of
these halves is equal to the number itself. Write a program to generate and print all four digits tech numbers.
Mock Test
2023-24
Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins
Example:
Answer
Question 8 [15]
Define a class to accept values in integer array of size 10. Find sum of one digit number and sum of two digit
numbers entered. Display them separately.
Example:
Input: a[ ] = {2, 12, 4, 9, 18, 25, 3, 32, 20, 1}
Output:
Sum of one digit numbers : 2 + 4 + 9 + 3 + 1 = 19
Sum of two digit numbers : 12 + 18 + 25 + 32 + 20 = 107
import java.util.Scanner;
Grade: 10 TotalMarks: 40
Subject: Computer Applications Duration: 50mins
arr[i] = in.nextInt();
}
}
}
Note: Pattern for the documentation comment and variable description table as given below
is to be followed for questions 3 to 8: -
Sample: Documentation comment
/**
*A program to input a set of 20 letters
*Convert each letter into upper case
*and find and display the number of vowels and number of consonants present in the set of given letters
* @author (ABC)
* @version (Java_BlueJ)
*/