Solved 2010 Specimen Paper
Solved 2010 Specimen Paper
Section A
Question 1
Answer
Java compiler converts Java source code into an intermediate binary code called Bytecode.
Bytecode can't be executed directly on the processor. It needs to be converted into Machine
Code first.
(b) What do you understand by type conversion? How is implicit conversion different from
explicit conversion?
Answer
The process of converting one predefined type into another is called type conversion. In an
implicit conversion, the result of a mixed mode expression is obtained in the higher most
data type of the variables without any intervention by the user. For example:
int a = 10;
float b = 25.5f, c;
c = a + b;
In case of explicit type conversion, the data gets converted to a type as specified by the
programmer. For example:
int a = 10;
double b = 25.5;
Answer
break statement, it is used to jump out of a switch statement or a loop. continue statement,
it is used to skip the current iteration of the loop and start the next iteration.
Answer
An exception is an event, which occurs during the execution of a program, that disrupts the
normal flow of the program's instructions. Two exception handling blocks are try and catch.
Answer
1. Methods help to manage the complexity of the program by dividing a bigger complex
task into smaller, easily understood tasks.
Question 2
Page 1 of 5
(a) State the purpose and return data type of the following String functions:
1. indexOf()
2. compareTo()
Answer
1. indexOf() returns the index within the string of the first occurrence of the specified
character or -1 if the character is not present. Its return type is int.
(b) What is the result stored in x, after evaluating the following expression?
int x = 5;
x = x++ * 2 + 3 * --x;
Answer
x = x++ * 2 + 3 * --x
⇒x=5*2+3*5
⇒ x = 10 + 15
⇒ x = 25
Answer
They are declared using keyword They are declared without using keyword
'static'. 'static'.
All objects of a class share the same Each object of the class gets its own copy of
copy of Static data members. Non-Static data members.
They can be accessed using the class They can be accessed only through an object
name or object. of the class.
Answer
length length()
It gives the length of an array i.e. the number of It gives the number of characters
elements stored in an array. present in a string.
Answer
Page 2 of 5
Private members are only accessible inside the class in which they are defined and they
cannot be inherited by derived classes. Protected members are also only accessible inside
the class in which they are defined but they can be inherited by derived classes.
Question 3
(a) What do you understand by the term data abstraction? Explain with an example.
Answer
Data Abstraction refers to the act of representing essential features without including the
background details or explanations. A Switchboard is an example of Data Abstraction. It
hides all the details of the circuitry and current flow and provides a very simple way to
switch ON or OFF electrical appliances.
int m = 2;
int n = 15;
m++;
--n;
Answer
Output
m=6
n=14
Explanation
As there are no curly braces after the for loop so only the statement m++; is inside the loop.
Loop executes 4 times so m becomes 6. The next statement --n; is outside the loop so it is
executed only once and n becomes 14.
char x = 'A';
int m;
Answer
Output
m = 97
Explanation
Page 3 of 5
The condition x == 'a' is false as X has the value of 'A'. So, the ternary operator returns 'a'
that is assigned to m. But m is an int variable not a char variable. So, through implicit
conversion Java converts 'a' to its numeric ASCII value 97 and that gets assigned to m.
(c) Analyze the following program segment and determine how many times the loop will be
executed and what will be the output of the program segment.
int k = 1, i = 2;
while(++i < 6)
k *= i;
System.out.println(k);
Answer
Output
60
Explanation
This table shows the change in values of i and k as while loop iterates:
i k Remarks
2 1 Initial values
3 3 1st Iteration
4 12 2nd Iteration
5 60 3rd Iteration
Notice that System.out.println(k); is not inside while loop. As there are no curly braces so
only the statement k *= i; is inside the loop. The statement System.out.println(k); is outside
the while loop, it is executed once and prints value of k which is 60 to the console.
(d) Give the prototype of a function check which receives a character ch and an integer n
and returns true or false.
Answer
Answer
Page 4 of 5
2. Check if the second character of a string str is in uppercase.
Answer
1. Math.max(-17, -19)
2. Math.ceil(7.8)
Answer
1. -17
2. 8.0
Answer
A class can create objects of itself with different characteristics and common behaviour. So,
we can say that an Object represents a specific state of the class. For these reasons, an
Object is called an Instance of a Class.
Answer
import keyword is used to import built-in and user-defined packages into our Java program.
Page 5 of 5