Java Isce Class 10 Short Question
Java Isce Class 10 Short Question
Question 1(i)
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)
1. relational
2. logical
3. arithmetic
4. assignment
Answer
relational
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:
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)
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)
1. every
2. all
3. case
4. each
Answer
case
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
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)
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)
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)
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)
1. java.lang
2. java.util
3. java.io
4. java.awt
Answer
java.lang
Question 1(xiv)
1. Inheritance
2. Polymorphism
3. Abstraction
4. Encapsulation
Answer
Polymorphism
Question 1(xv)
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.
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
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)
Answer
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)
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)
System.out.print(Character.toLowerCase('1'));
1. 0
2. 1
3. A
4. true
Answer
Question 2(i)
Answer
Math.pow((p + q) , 2)
Question 2(ii)
x = x++ + ++x + x
Answer
Output
10
Explanation
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
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
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?
Logical error.
Modified program:
Explanation
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)
Question 2(vi)
(a) "ARTIFICIAL".indexOf('I')
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)
Answer
1. break statement
2. continue statement
Question 2(viii)
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
Answer
(a) 0
(b) null
Question 2(x)
Place all elements of P array and Q array in the array R one after the other.
Answer
Section A
Question 1
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.
Answer
Keywords are reserved words that have a special meaning to the Java compiler. Example: class,
public, int, etc.
Answer
1. java.io
2. java.util
(d) Name the type of error ( syntax, runtime or logical error) in each case given below:
Answer
1. Runtime Error
2. Syntax Error
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
Answer
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:
Answer
1. Explicit Cast.
2. Implicit Cast.
Answer
They represent the values received by the called They represent the values passed to the called
function. function.
Answer
Answer
1. public
2. private
Question 3
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
1. Math.ceil(4.2)
2. Math.abs(-4)
Answer
1. 5.0
2. 4
Answer
A Parameterised constructor receives parameters at the time of creating an object and initializes
the object with the received values.
T=√A2+B2+C2
Answer
if (x%2 == 0)
System.out.print("EVEN");
else
System.out.print("ODD");
Answer
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:
Output
5
10
Loop executes 3 times.
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
Answer
1. isLetterOrDigit(char)
2. replace(char, char)
Answer
1. boolean
2. String
Section A
Question 1
Precedence of operators refers to the order in which the operators are applied to the operands in
an expression.
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
Answer
1. Inheritance
2. Abstraction
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
Question 2
Answer
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
Answer
1. void
2. this
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
Answer
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.
Answer
(d) Rewrite the following program segment using the if..else statement:
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
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 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.
Answer
1. nextInt()
2. nextLine()