Java Model Test Papers for Icse

Topics: Java, Data type, Object-oriented programming Pages: 155 (22711 words) Published: June 26, 2013
Test Paper ONE

Question 1.
(a) Name two types of programming technique with examples. [4] Ans. Structured Programming (eg, C, BASIC);
Object Oriented Programming (eg, C++, JAVA)

(b) Explain type casting with an example. [2]

Ans.The explicit conversion of a wider data-type into a narrower data-type is called type-casting.

Example: double a = 3.567;
int b = (int) a / 10; //typecast double to int

(c) Evaluate a – (b++) * (--c), given a=2, b=3, c=9 [2]

Ans. 2 – 3 * 8 = -22

(d) Write the following expressions in Java: [2] square toot of the sum of squares of a and b

Ans. Math.pow ( (a*a + b*b) , 0.5)

Question 2.
(a) Give an example of local, of instance and of static variable [3] Ans. Static variable: Math.PI
Instance variable: b1.mks (where b1 is an object of class Boy) Local Variable: integer I in the loop: for (int I = 0; I < 5; I++)

(b) Mention two points of differences between binary and linear search. [4] Ans.
(i) Binary Search is faster, since the number of iterations is halved at each pass. Linear Search is slower, since the number of iteration is equal to the array length.

(ii) Binary Search does pre-supposes the array to be sorted. Linear Search does not suffer from this limitation.

(c) What does the keyword this mean in Java? Give an example. [3]

Ans.The keyword this refers to the current object.
It may be used to reference instance variables thus:
this-dot-variable (e. g. this.mks)

class Boy
int m1, m2;
Boy(int m1, int m2)
{this.m1 = m1; this.m2 = m2;}

Question 3.

(a) Give the output of the following and account for the difference in output. [4] int a = 5;
System.out.println (a = 4); //1
System.out.println (a == 4); //2

Ans. In (1) the output is 4, since the value 4 is assigned to int a. In (2) the output is False, since the logical operator returns a boolean.

(b) State any two features of OOP. [2]

Ans. Data Hiding, Encapsulation, Inheritance, etc.

(c) Which type of data are passed by reference and which ones by value? [2]
Ans. All primitive data types (char, int, float, String) are passed by value. Arrays and composite / user-defined data type are passed by reference.

(d) Give a single one-line command to sort an array. [2] What package would you include?
Ans. Arrays.sort(a); //where a[] is an array
import java.util*;

Question 4.

(a) Give the output: [2] int a = 4; int b = 7;
boolean tf1 = (a. > 5 && b < 9);
boolean tf2 = (a > 5 || b < 8);
System.out.println (tf1 + “***” + tf2);

Ans. Output: false***true

(b) Given int arr[][] = {
{ 3, 4},
{5, 6, 7},
{ 1 }

give the output of: arr.length, arr[2].length, arr[1][1]. [3]

Ans. Output: arr.length = 3; arr[2].length = 1; arr[1][1] = 6

(c) What is a recursive function (or recursive method)? [2]

Ans. When a function calls itself, it is called a recursion. Such methods are called recursive methods.
It may be used for purposes like:
(i) finding the factorial of a number
(ii) finding the sum of first ten...
Continue Reading

Please join StudyMode to read the full document

You May Also Find These Documents Helpful

  • Java Essay
  • Java Essay
  • The Papaer Java Test Questions and Answers Essay
  • Inroduction to Java Essay
  • Question and Model Test Paper
  • JAVA Essay
  • Java Essay

Become a StudyMode Member

Sign Up - It's Free