ICSE Computer Science Java Programs | IT Developer
IT Developer

Java Programs - Solved 2016 ICSE Computer Science Paper



Share with a Friend

Solved 2016 ICSE Computer Science Paper

Class 10 - ICSE Computer Science Solved Papers

Short Questions/Answers - ICSE 2016 Computer Science

Question 1

(a) Define encapsulation.
Wrapping up of data and functions into a single unit called class is known as encapsulation.

(b) What are keywords? Give an example.
Keywords are the words that convey a special meaning to the language compiler. Example: void.

(c) Name any two library packages.
java.lang and java.io are two library packages.

(d) Name the type of error (syntax, runtime or logical error) in each case given below:
(i) Math.sqrt(36 - 45) – runtime error.
(ii) int a;b;c; – syntax error.

(e) If int x[] = {4, 3, 7, 8, 9, 10}; what are the values of p and q?
(i) p = x.length
6
(ii) q = x[2] + x[5] * x[1]
7 + 10 * 3
= 7 + 30
= 37.

Question 2

(a) State the difference between == operator and equals() method.
The == operator compares two numeric or character values for equality.
The equals() method compares the contents of two String values for equality.

(b) What are the types of casting shown by the following examples?
(i) char c = (char)120; (Explicit type casting)
(ii) int x = \'t\'; (Implicit type casting)

(c) Differentiate between formal parameter and actual parameter.
Formal parameters appear in the method definition.
Actual parameter appear in the method call statement.

(d) Write the function prototype of the following:
A function posChar which takes a string argument and a character argument and returns an integer value.
int posChar(String s, char ch)

(e) Name any two types of access specifiers.
public and private are two types of access specifiers.

Question 3

(a) Give the output of the following string functions:
(i) "MISSISSIPPI".indexOf(\'S\') + "MISSISSIPPI".lastIndexOf(\'I\')
2 + 10 = 12
(ii) "CABLE".compareTo("CADET")
66 – 68 = -2

(b) Give the output of the following Math functions:
(i) Math.ceil(4.2)
5.0
(ii) Math.abs(-4)
4

(c) What is a parameterized constructor?
Parameterized constructor are the ones that receive parameters and initialize objects with received values.

(d) Write down Java expression for:
T = √(A2 + B2 + C2)
T = Math.sqrt(A * A + B * B + C * C)

(e) Rewrite the following using ternary operator:

if(x % 2 == 0)
    System.out.print("EVEN");
else
    System.out.print("ODD");

System.out.print(((x % 2 == 0)? "EVEN":"ODD"));

(f) Convert the following while loop to the corresponding for loop:

int m = 5, n = 10;
while(n >= 1){
    System.out.println(m * n);
    n--;
}
int m = 5, n = 10;
for(; n >= 1; n--)
    System.out.println(m * n);

(g) Write one difference between primitive data types and composite data types.
Primitive data types come as part of the language.
Composite data types are constructed from primitive data types.

(h) Analyze the given program segment and answer the following questions:
(i) Write the output of the program segment.
(ii) How many times does the body of the loop gets executed?

for(int m = 5; m <= 20; m += 5){
    if(m % 3 == 0)
        break;
    else
        if(m % 5 == 0)
            System.out.println(m);
    continue;
}

OUTPUT:
5
10

The body of the loop executes 3 times.

(i) Give the output of the following expression:
a += a++ + ++a + --a + a--; when a = 7.

a = a + a++ + ++a + –a + a–;
= 7 + 7 + 9 + 8 + 8
= 14 + 9 + 8 + 8
= 23 + 8 + 8
= 31 + 8
= 39.

(j) Write the return type of the following library functions:
(i) isLetterOrDigit(char)boolean
(ii) replace(char, char)String