0% found this document useful (0 votes)
34 views

Java Isce Class 10 Short Question

sample paper with solutions regarding ICSE syllabus of computer application
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
34 views

Java Isce Class 10 Short Question

sample paper with solutions regarding ICSE syllabus of computer application
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 24

Section A

Question 1(i)

Name the feature of java depicted in the below picture.

1. Encapsulation
2. Inheritance
3. Abstraction
4. Polymorphism

Answer

Inheritance

Reason — The given picture shows the relationship of a parent (father) and child. Just like a
child inherits some characteristics from his parents, inheritance enables new classes (derived
class) to receive or inherit the properties and methods of existing classes (base class).

Question 1(ii)

The expression which uses >= operator is known as:

1. relational
2. logical
3. arithmetic
4. assignment
Answer

relational

Reason — Relational expressions are constructed using relational operators — equal to ( == ),


not equal to ( != ), less than ( < ), less than equal to ( <= ), greater than ( > ), greater than equal to
( >= )

Question 1(iii)

Ternary operator is a:

1. logical operator
2. arithmetic operator
3. relational operator
4. conditional operator

Answer

conditional operator

Reason — Ternary operator is a conditional operator as it evaluates the given condition. Its
syntax is as follows:

condition? expression 1 : expression 2


If the condition is true then result of ternary operator is the value of expression 1. Otherwise the
result is the value of expression 2.

Question 1(iv)

When primitive data type is converted to a corresponding object of its class, it is called:

1. Boxing
2. Unboxing
3. explicit type conversion
4. implicit type conversion

Answer

Boxing

Reason — Boxing is the conversion of primitive data type into an object of its corresponding
wrapper class.

Question 1(v)
The number of bytes occupied by a character array of 10 elements.

1. 20 bytes
2. 60 bytes
3. 40 bytes
4. 120 bytes

Answer

20 bytes

Reason — A char data type occupies '2' bytes in the memory. Thus, 10 char type elements
occupy (10 x 2) = 20 bytes in memory.

Question 1(vi)

The method of Scanner class used to accept a double value is:

1. nextInt()
2. nextDouble()
3. next()
4. nextInteger()

Answer

nextDouble()

Reason — The nextDouble() function reads the next token entered by the user as a double value.

Question 1(vii)

Among the following which is a keyword:

1. every
2. all
3. case
4. each

Answer

case

Reason — case is a keyword. It is used to define switch case construct.

Question 1(viii)
The output of Math.round(6.6) + Math.ceil(3.4) is:

1. 9.0
2. 11.0
3. 10.0
4. 11

Answer

11.0

Reason — The given expression is evaluated as follows:


Math.round(6.6) + Math.ceil(3.4)
⇒ 7 + 4.0
⇒ 11.0

Math.round() rounds off its argument to the nearest mathematical integer and returns its value as
an int or long type. Math.ceil method returns the smallest double value that is greater than or
equal to the argument and is equal to a mathematical integer. In the addition operation, the type
of result is promoted to a double as one operand is double. Hence, the result is 11.0.

Question 1(ix)

Name the type of error, if any in the following statement:

System.out.print("HELLO")

1. logical
2. no error
3. runtime
4. syntax

Answer

syntax

Reason — The given statement is missing a terminator ( ; ) at the end. Thus, it has a syntax
error.

Question 1(x)

Java statement to access the 5th element of an array is:

1. X[4]
2. X[5]
3. X[3]
4. X[0]

Answer

X[4]

Reason — Array indexes start from 0. So, X[4] refers to the 5th element of the array.

Question 1(xi)

The output of "Remarkable".substring(6) is:

1. mark
2. emark
3. marka
4. able

Answer

able

Reason — "Remarkable".substring(6) will extract a substring starting from the character at index
6 (i.e., 7th character of the string) which is 'a' till the end of the string. Hence the output is able.

Question 1(xii)

Which of the following is the wrapper class for the data type char?

1. String
2. Char
3. Character
4. Float

Answer

Character

Reason — Character is the wrapper class for the data type char.

Question 1(xiii)

Name the package that contains wrapper classes:

1. java.lang
2. java.util
3. java.io
4. java.awt

Answer

java.lang

Reason — Wrapper classes are present in java.lang package.

Question 1(xiv)

Constructor overloading follows which principle of Object Oriented programming?

1. Inheritance
2. Polymorphism
3. Abstraction
4. Encapsulation

Answer

Polymorphism

Reason — In object-oriented programming, Polymorphism provides the means to perform a


single action in multiple different ways and constructor overloading follows Polymorphism
principle of Object Oriented programming wherein a constructor having the same name behaves
differently with different arguments.

Question 1(xv)

Which of the following is a valid Integer constant:


i. 4
ii. 4.0
iii. 4.3f
iv. "four"

1. Only i
2. i and iii
3. ii and iv
4. i and ii

Answer

Only i
Reason — Integer constants represent whole number values only. Thus, 4 is an integer constant.
4.0 is a double constant, 4.3f is a float constant while "four" is a String constant.

Question 1(xvi)

The method compareTo() returns ............... when two strings are equal and in lowercase :

1. true
2. 0
3. 1
4. false

Answer

Reason — compareTo() method compares two strings lexicographically and returns the
difference between the ASCII values of the first differing characters in the strings. Here, the
strings are equal so the difference is 0.

Question 1(xvii)

Assertion (A): In Java, statements written in lower case letter or upper case letter are treated as
the same.

Reason (R): Java is a case sensitive language.

1. Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of
Assertion (A)
2. Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation
of Assertion (A)
3. Assertion (A) is true and Reason (R) is false
4. Assertion (A) is false and Reason (R) is true

Answer

Assertion (A) is false and Reason (R) is true

Reason — In Java, statements written in lower case letter or upper case letter are treated
differently as Java is a case sensitive language.

Question 1(xviii)

Read the following text, and choose the correct answer:


A class encapsulate Data Members that contains the information necessary to represent the class
and Member methods that perform operations on the data member.

What does a class encapsulate?

1. Information and operation


2. Data members and Member methods
3. Data members and information
4. Member methods and operation

Answer

Data members and Member methods

Reason — A class encapsulates state and behavior by combining data and functions into a single
unit. The state of an object is represented by its member variables and behaviour is represented
by member methods.

Question 1(xix)

Assertion (A): Call by value is known as pure method.

Reason (R): The original value of variable does not change as operation is performed on copied
values.

1. Both Assertion (A) and Reason (R) are true and Reason (R) is a correct explanation of
Assertion (A)
2. Both Assertion (A) and Reason (R) are true and Reason (R) is not a correct explanation
of Assertion (A)
3. Assertion (A) is true and Reason (R) is false
4. 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)

Reason — Call by value is known as pure method as it does not modify the value of original
variables. The original value of variable does not change as operation is performed on copied
values.

Question 1(xx)

What will be the output for:

System.out.print(Character.toLowerCase('1'));
1. 0
2. 1
3. A
4. true

Answer

Reason — In Java, the Character.toLowerCase(char ch) method is used to convert a


given character to its lowercase equivalent, if one exists. If the character is already in lowercase
or there is no lowercase equivalent, it will return the original character.

Question 2(i)

Write the Java expression for (p + q)2.

Answer

Math.pow((p + q) , 2)

Question 2(ii)

Evaluate the expression when the value of x = 2:

x = x++ + ++x + x
Answer

Output

10

Explanation

Initially, x = 2. The expression is calculated as follows:

x = x++ + ++x + x
x = 2 + ++x + x (x = 3)
x=2+4+x (x = 4)
x=2+4+4 (x = 4)
x = 10

Question 2(iii)
The following code segment should print "You can go out" if you have done your homework
(dh) and cleaned your room (cr). However, the code has errors. Fix the code so that it compiles
and runs correctly.

boolean dh = True;
boolean cr= true;
if (dh && cr)
System.out.println("You cannot go out");
else
System.out.println("You can go out");
Answer

The corrected code is as follows:

boolean dh = true;
boolean cr= true;
if (dh && cr)
System.out.println("You can go out");
else
System.out.println("You cannot go out");

Explanation

1. boolean dh = True; — Here, True should be in lowercase as true.


2. println statements of if-else should be interchanged because if both dh (done homework)
and cr (cleaned room) are true then the person can go out.

Question 2(iv)

Sam executes the following program segment and the answer displayed is zero irrespective of
any non zero values are given. Name the error. How the program can be modified to get the
correct answer?

void triangle(double b, double h)


{
double a;
a = 1/2 * b * h;
System.out.println("Area=" + a);
}
Answer

Logical error.

Modified program:

void triangle(double b, double h)


{
double a;
a = 1.0/2 * b * h;
System.out.println("Area=" + a);
}

Explanation

The statement is evaluated as follows:

a = 1/2 * b * h;
a = 0 * b * h; (1/2 being integer division gives the result as 0)
a = 0 (Since anything multiplied by 0 will be 0)

To avoid this error, we can replace '1/2' with '1.0/2'. Now the expression will be evaluated as
follows:

a = 1.0/2 * b * h;
a = 0.5 * b * h; (The floating-point division will result in result as as 0.5)

This will give the correct result for the given code.

Question 2(v)

How many times will the following loop execute? What value will be returned?

int x = 2;
int y = 50;
do{
++x;
y -= x++;
}
while(x <= 10);
return y;
Answer

The loop will execute 5 times and the value returned is 15.
Explanation

Iteration X Y Remark

2 50 Initial values

1 3 47 x = 4 (3 + 1), y = 47 (50 - 3)

2 5 42 x = 6 (5 + 1), y = 42 (47 - 5)

3 7 35 x = 8 (7 + 1), y = 35 (42 - 7)

4 9 26 x = 10 (8 + 1), y = 26 (35 - 9)

5 11 15 x = 12 (11 + 1), y = 15 (26 - 11)

11 15 Condition becomes false. Loop terminates.

Question 2(vi)

Write the output of the following String methods:

(a) "ARTIFICIAL".indexOf('I')

(b) "DOG and PUPPY".trim().length()

Answer

(a)

Output

Explanation

indexOf() returns the index of the first occurrence of the specified character within the string or -
1 if the character is not present. First occurrence of 'I' in "ARTIFICIAL" is at index 3 (a string
begins at index 0).

(b)
Output

13

Explanation

trim() removes all leading and trailing space from the string and length() returns the length of the
string i.e., the number of characters present in the string. Thus, the output is 13.

Question 2(vii)

Name any two jump statements.

Answer

Two jump statements are:

1. break statement
2. continue statement

Question 2(viii)

Predict the output of the following code snippet:

String a = "20";
String b = "23";
int p = Integer.parseInt(a);
int q = Integer.parseInt(b);
System.out.print(a + "*" + b);
Answer

Output

20*23

Explanation

Integer.parseInt() method will convert the strings a and b to their corresponding numerical
integers — 20 and 23. In the statement, System.out.print(a + "*" + b); a, b,
and "*" are strings so + operator concatenates them and prints 20*23 as the output.

Question 2(ix)

When there is no explicit initialization, what are the default values set for variables in the
following cases?
(a) Integer variable

(b) String variable

Answer

(a) 0

(b) null

Question 2(x)

int P[ ] = {12, 14, 16, 18};


int Q[ ] = {20, 22, 24};

Place all elements of P array and Q array in the array R one after the other.

(a) What will be the size of array R[ ] ?

(b) Write index position of first and last element?

Answer

int R[ ] = {12, 14, 16, 18, 20, 22, 24};

(a) Size of array P[ ] = 4


Size of array Q[ ] = 3
Size of array R[ ] = 7 (4 + 3).

(b) Index position of first element is 0.


Index position of last element is 6.

Section A

Question 1

(a) Define Encapsulation.

Answer

Encapsulation is a mechanism that binds together code and the data it manipulates. It keeps them
both safe from the outside world, preventing any unauthorised access or misuse. Only member
methods, which are wrapped inside the class, can access the data and other methods.

(b) What are keywords ? Give an example.

Answer
Keywords are reserved words that have a special meaning to the Java compiler. Example: class,
public, int, etc.

(c) Name any two library packages.

Answer

Two library packages are:

1. java.io
2. java.util

(d) Name the type of error ( syntax, runtime or logical error) in each case given below:

1. Math.sqrt (36 – 45)


2. int a;b;c;

Answer

1. Runtime Error
2. Syntax Error

(e) If int x[] = { 4, 3, 7, 8, 9, 10}; what are the values of p and q ?

1. p = x.length
2. q = x[2] + x[5] * x[1]

Answer

1. 6
2. q = x[2] + x[5] * x[1]
q = 7 + 10 * 3
q = 7 + 30
q = 37

Question 2

(a) State the difference between == operator and equals() method.

Answer

equals() ==

It is a method It is a relational operator


equals() ==

It is used to check if the contents of two strings It is used to check if two variables refer to the same
are same or not object in memory

Example: Example:
String s1 = new String("hello"); String s1 = new String("hello");
String s2 = new String("hello"); String s2 = new String("hello");
boolean res = s1.equals(s2); boolean res = s1 == s2;
System.out.println(res); System.out.println(res);

The output of this code snippet is true as contents The output of this code snippet is false as s1 and s2
of s1 and s2 are the same. point to different String objects.

(b) What are the types of casting shown by the following examples:

1. char c = (char) 120;


2. int x = ‘t’;

Answer

1. Explicit Cast.
2. Implicit Cast.

(c) Differentiate between formal parameter and actual parameter.

Answer

Formal parameter Actual parameter

Actual parameters appear in function call


Formal parameters appear in function definition.
statement.

They represent the values received by the called They represent the values passed to the called
function. function.

(d) Write a function prototype of the following:


A function PosChar which takes a string argument and a character argument and returns
an integer value.

Answer

int PosChar(String s, char ch)


(e) Name any two types of access specifiers.

Answer

1. public
2. private

Question 3

(a) Give the output of the following string functions:

1. "MISSISSIPPI".indexOf('S') + "MISSISSIPPI".lastIndexOf('I')
2. "CABLE".compareTo("CADET")

Answer

1. 2 + 10 = 12
2. ASCII Code of B - ASCII Code of D
⇒ 66 - 68
⇒ -2

(b) Give the output of the following Math functions:

1. Math.ceil(4.2)
2. Math.abs(-4)

Answer

1. 5.0
2. 4

(c) What is a parameterized constructor ?

Answer

A Parameterised constructor receives parameters at the time of creating an object and initializes
the object with the received values.

(d) Write down java expression for:

T=√A2+B2+C2
Answer

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");
Answer

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--;
}
Answer

int m = 5;
for (int n = 10; n >= 1; n--) {
System.out.println(m*n);
}
(g) Write one difference between primitive data types and composite data types.

Answer

Primitive Data Types are built-in data types defined by Java language specification whereas
Composite Data Types are defined by the programmer.

(h) Analyze the given program segment and answer the following questions:

1. Write the output of the program segment.


2. 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;
}
Answer

Output
5
10
Loop executes 3 times.

Below dry run of the loop explains its working.

m Output Remarks

5 5 1st Iteration

5
10 2nd Iteration
10

5
15 3rd Iteration — As m % 3 becomes true, break statement exists the loop.
10

(i) Give the output of the following expression:

a+= a++ + ++a + --a + a-- ; when a = 7

Answer

a+= a++ + ++a + --a + a--


⇒ a = a + (a++ + ++a + --a + a--)
⇒ a = 7 + (7 + 9 + 8 + 8)
⇒ a = 7 + 32
⇒ a = 39

(j) Write the return type of the following library functions:

1. isLetterOrDigit(char)
2. replace(char, char)

Answer

1. boolean
2. String

Section A

Question 1

(a) What is meant by precedence of operators?


Answer

Precedence of operators refers to the order in which the operators are applied to the operands in
an expression.

(b) What is a literal?

Answer

Literals are data items that are fixed data values. Java provides different types of literals like:

1. Integer Literals
2. Floating-Point Literals
3. Boolean Literals
4. Character Literals
5. String Literals
6. null Literal

(c) State the Java concept that is implemented through:

1. a superclass and a subclass.


2. the act of representing essential features without including background details.

Answer

1. Inheritance
2. Abstraction

(d) Give a difference between a constructor and a method.

Answer

Constructor has the same name as class name whereas function should have a different name
than class name.

(e) What are the types of casting shown by the following examples?

1. double x = 15.2;
int y = (int) x;

2. int x = 12;
long y = x;

Answer

1. Explicit Type Casting


2. Implicit Type Casting

Question 2

(a) Name any two wrapper classes.

Answer

Two wrapper classes are:

1. Integer
2. Character

(b) What is the difference between a break statement and a continue statement when they
occur in a loop?

Answer

When the break statement gets executed, it terminates its loop completely and control reaches to
the statement immediately following the loop. The continue statement terminates only the
current iteration of the loop by skipping rest of the statements in the body of the loop.

(c) Write statements to show how finding the length of a character array char[] differs
from finding the length of a String object str.

Answer

Java code snippet to find length of character array:

char ch[] = {'x', 'y', 'z'};


int len = ch.length
Java code snippet to find length of String object str:

String str = "Test";


int len = str.length();
(d) Name the Java keyword that:

1. indicates that a method has no return type.


2. stores the address of the currently-calling object.

Answer

1. void
2. this

(e) What is an exception?


Answer

An exception is an abnormal condition that arises in a code sequence at run time. Exceptions
indicate to a calling method that an abnormal condition has occurred.

Question 3

(a) Write a Java statement to create an object mp4 of class Digital.

Answer

Digital MP4 = new Digital();


(b) State the values stored in the variables str1 and str2:

String s1 = "good";
String s2 = "world matters";
String str1 = s2.substring(5).replace('t', 'n');
String str2 = s1.concat(str1);
Answer

Value stored in str1 is " manners" and str2 is "good manners". (Note that str1 begins with a
space.)

Explanation

s2.substring(5) gives a substring from index 5 till the end of the string which is " matters". The
replace method replaces all 't' in " matters" with 'n' giving " manners". s1.concat(str1) joins
together "good" and " manners" so "good manners" is stored in str2.

(c) What does a class encapsulate?

Answer

A class encapsulates data and behavior.

(d) Rewrite the following program segment using the if..else statement:

comm = (sale > 15000)? sale * 5 / 100 : 0;


Answer

if(sale > 15000)


comm = sale * 5 / 100;
else
comm = 0;
(e) How many times will the following loop execute? What value will be returned?

int x = 2, y = 50;
do{
++x;
y -= x++;
}while(x <= 10);
return y;
Answer

The loop will run 5 times and the value returned is 15.

(f) What is the data type that the following library functions return?

1. isWhitespace(char ch)
2. Math.random()

Answer

1. boolean
2. double

(g) Write a Java expression for:

ut+½ft2
Answer

u * t + 1 / 2.0 * f * t * t

(h) If int n[] = {1, 2, 3, 5, 7, 9, 13, 16}, what are the values of x and y?

x = Math.pow(n[4], n[2]);
y = Math.sqrt(n[5] + n[7]);

Answer

x = Math.pow(n[4], n[2]);
⇒ x = Math.pow(7, 3);
⇒ x = 343.0;

y = Math.sqrt(n[5] + n[7]);
⇒ y = Math.sqrt(9 + 16);
⇒ y = Math.sqrt(25);
⇒ y = 5.0;

(i) What is the final value of ctr when the iteration process given below, executes?

int ctr = 0;
for(int i = 1; i <= 5; i++)
for(int j = 1; j <= 5; j += 2)
++ctr;
Answer

The final value of ctr is 15.

The outer loop executes 5 times. For each iteration of outer loop, the inner loop executes 3 times.
So the statement ++ctr; is executed a total of 5 x 3 = 15 times.

(j) Name the method of Scanner class that:

1. is used to input an integer data from the standard input stream.


2. is used to input a String data from the standard input stream.

Answer

1. nextInt()
2. nextLine()

You might also like