Mock Test 1
Computer Science
FM: 35
Time: 1 hr. 30 minutes
Answer the following questions. The number within brackets beside every section
represents the concerned score.
Section A (7 x 1 = 7 marks)
1. Give one advantage of using recursion over iteration.
2. What is an abstract method?
3. Define overriding.
4. “Constructor of the derived class gets executed before the constructor of the base
class” - is it true or false?
5. N-L-R represents (N = Root, L=Left Child, R=Right Child)
(i) In-order
(ii) Pre-order
(iii) Post-order
(iv) None
6. Give the output of the following string methods:
"SUBMISSION ".indexOf('S')+ " SUBMISSION ".lastIndexOf('I')
7. Write the statement in Java to extract the word “NATION” from the word “ASSASINATION”.
Section B (4 x 2 = 8 marks)
8. What is an interface? How is it different from a class?
9. The following function Check() is a part of some class. What will the function Check()
return when the values of both ‘m’ and ‘n’ is equal to 5? Show the dry run/working.
int Check (int m, int n)
{
if(n = = 1)
return - m --;
else
return + + m + Check (m, -- n);
}
10. From the class declaration given below, state the nature of the identifiers A, B, C and
D:
class A extends B implements C, D
11.
P
B R
S T U V
X Y
Observe the above tree and write the Pre-order and In-order traversal sequences.
Section C (4 x 5 = 20 marks)
12. Write a program in Java to accept some word and check if it is a palindrome. 4
13. Write a program in Java to take a positive integer ‘n’ as input to find out all the
Pythagorean triplets <a, b, c> such that a<b<c and a2 + b2 = c2, within 1 to ‘n’. 6
14.Find output: 4
Find output of the following code fragment:
class Q1{
public static void main(String args[]){
int a=4;
int b=8;
if((b-a--)>=a)
{
if((b+a)%2==1)
System.out.println(a*b);
else
System.out.println(b+a);
}
}
15. Write a program in Java to accept a square matrix A of order ‘n’, to be taken as input
and to generate a symmetric matrix, using A. 6