Class 10 ICSE Practice Paper 2
Class 10 ICSE Practice Paper 2
1) System.out.println(“a”+0+’A’);
a) a0A b) a065c) a65 d) a4564
2) System.out.println(‘A’+’1’+“B”);
a) A1B b) A49B c) 651B d) 114B
3) System.out.print(‘A’+’1’);
a) A1 b) 651 c) 6549 d) 114
4) System.out.println(‘B’+9+’z’);
a) B9z b) 669122 c) 245 d) 197
5) System.out.println(“ADD”+(‘A’+’B’));
ADDAB b) ADD6566 c) ADD131 d) ADDA+B
15) Which operation will be performed first in the given expression: ++x / b+c * d % e
a) ++ b) + c) * d) %
24) The prototype of a function Show(), that returns a float and takes two integer arguments is:
a) void Show(int a,int b) b) float Show(int a, int b)
c) float Show(int a) d) static Show(int a,int b)
29) if ( n > m)
System.out.print(“GOOD”);
System.out.print(“LUCK”);
else
System.out.print(“DONE”);
What will be the output if n=6 and m=4?
a)GOOD b) GOODLUCK c) DONE d) Error
30) System.out.println(Math.ceil(-9.4)+Math.sqrt(9.0));
a) 6.0 b) -6.0 c) -5.0 d) 5.0
31) Which of the following statements is not true about a static method?
a. It can be invoked without creating an object.
b. It can be called by a non-static method.
c. It can access instance variables directly.
d. It can access static variables directly.
34) The condition of an IF statement evaluates to boolean only if the expression contains?
a. logical operators
b. relational operators
c. boolean operands
d. All
36) An IF-ELSE statement is better than a SWITCH statement in which scenario below?
a. Checking for More-than condition
b. Checking for Less-than condition
c. Checking for Ranges
d. all
39) What is the output of the below Java program with a SWITCH
statement? int points=6;
switch(points)
{
case 6: ;
case 7: System.out.println("PASS");break;
case 8: ;
case 9: System.out.println("Excellent");break;
case 10: System.out.println("Outstanding");
break; default: System.out.println("FAIL");
}
a. PASS
b. Excellent
c. Outstanding
d. FAIL
43) What is the output of the Java code snippet with Ternary operator?
int num = false?10:20;
System.out.println(num);
a) 10
b) 20
c) 0
d) Compiler error
44) What are the types of data that can be used along with Relational operators in Java?
a. char, boolean, Object
b. byte, short, int, long
c. float, double
d. All the above
47) In java control statements break, continue, return, try-catch-finally and assert belongs to?
A. Selection statements
B. Loop Statements
C. Transfer statements
D. Pause Statement
Answer: _______________
48) Which provides runtime environment for java byte code to be executed?
A. JDK
B. JVM
C. JRE
D. JAVAC
Answer: _______________
55) Which symbol is used to contain the values of automatically initialized arrays?
A. Brackets
B. Braces
C. Parentheses
D. Comma
Answer: _______________
56) Which of these operators is used to allocate memory to array variable in Java?
A. alloc
B. malloc
C. new malloc
D. new
Answer: _______________
57) Which of these is returned by Greater Than, Less Than and Equal To (i.e Relational) operator ?
A. Float
B. Integer
C. Boolean
D. Double
Answer: _______________
58) Which statement transfer execution to different parts of your code based on the value of an expression?
A. If
B. Switch
C. Nested-if
D. if-else-if
Answer: _______________
69) Evaluate the following Java expression, if x=3, y=5, and z=10:
++z + y - y + z + x++
24
23
20
25
Answer: _______________
71) Given that Student is a class, how many reference variables and objects are created by the
following code?
Student studentName, studentId;
studentName = new Student();
Student stud_class = new Student();
Three reference variables and two objects are created.
Two reference variables and two objects are created.
One reference variable and two objects are created.
Three reference variables and three objects are created.
Answer: _______________
77) Read the following program and answer the questions given below
class Method
{
double compute(int a, int b)
{
return (a+b)/2.0;
}
static void main()
{
Method ob=new Method():
_______A______;
}
}
Which of the following statements will correctly invoke the method compute() in line ‘A’;
System.out.println(ob.compute(15));
ob.compute(15,19);
ob.compute();
System.out.println(ob.compute(15,19));
Answer: _______________
78) Which of the following statements is not the correct way to declare overloaded methods.
void area(int x)
void area(float x)
int area(int x)
void area(double x)
Answer: _______________
79) Every loop in Java has a condition that should be ___ in order to proceed for execution.
FALSE
TRUE
Answer: _______________
80) A WHILE loop in Java executes the statements at least once even the condition is not satisfied.
a) FALSE
b) TRUE
Answer: _______________
82) What is the output of the below Java program with WHILE, BREAK and CONTINUE?
int cnt=0;
while(true)
{
if(cnt > 4)
break;
if(cnt==0)
{
cnt++;
continue;
}
System.out.print(cnt + ",");
cnt++;
}
a) 0,1,2,3,4,
b) 1,2,3,4,
c) 1,2,3,4
d) Compiler error
Answer: _______________
83) What is the main difference between a WHILE and a DO-WHILE loop in Java?
a) WHILE loop executes the statements inside of it at least once even if the condition is false.
b) DO-WHILE loop executes the statements inside of it at least once even if the condition is false.
c) WHILE loop is fast.
d) DO-WHILE loop is fast.
Answer: _______________
87) Which is the keyword used to specify the DEFAULT access modifier in java?
a. default
b. bydefault
c. normal
d. There is no keyword
92) Which of these is used to access a member of class before object of that class is created?
a) public
b) private
c) static
d) protected
93) Which of these is used as a default for a member of a class if no access specifier is used for it?
a) private
b) public
c) public, within its own package
d) protected
94) What is the process by which we can control what parts of a program can access the members of
a class?
a) Polymorphism
b) Abstraction
c) Encapsulation
d) Recursion
100) Can you access a default member of a class from a class outside the current package?
a. No
b. Yes
103) Choose the correct Java code snippet with access modifiers below?
a. class ABC { }
b. private protected class ABC { }
c. protected public class ABC { }
d. protected private class ABC { }
104) Visible in the classes and subclasses in the same package and subclasses in other packages.
a. private
b. public
c. protected
d. default
105) The __ access specifier used in a class cannot be accessed by subclass in the same package.
a. private
b. public
c. protected
d. default
106) Which among the following can restrict class members to get inherited?
a) Private
b) Protected
c) Public
d) All three
107) Which among the following allows class members to get inherited?
a) Private
b) Protected
c) Public
d) All three
108) Which access specifier is used when no access specifier is used with a member of class (java)?
a) Private
b) Default
c) Protected
d) Public
177) 25. Which of the following can be used when you know the number of times we
have to perform a task:
178) (a) for loop (b) while loop (c) do-while loop (d) All of the above
179) 26. What is the numerical range of a char in Java?
a) -128 to 127 b) 0 to 256 c) 0 to 32767 d) 0 to 65535
180) 27. Which of these coding types is used for data type characters in Java?
a) ASCII b) ISO-LATIN-1 c) UNICODE d) None of the
mentioned
182) 29. Which of these occupy first 0 to 127 in Unicode character set used for characters
in Java?
a) ASCII b) ISO-LATIN-1 c) None of the mentioned d) Both a
&b
184) 31. What is the stored in the object obj in following lines of code? box obj;
a) Memory address of allocated memory of object.
185) b) NULL
186) c) Any arbitrary pointer
a) Garbage
188) 33. Which of the following is a valid declaration of an object of class Box?
a) Box obj = new Box(); b) Box obj = new Box;
189) c) obj = new Box(); d) new Box obj;
190) 34. Which of these operators is used to allocate memory for an object?
a) malloc b) alloc c) new d) give
194) 37. What should be expression1 evaluate to in using ternary operator as in this line?
expression1 ? expression2 : expression3
a) Integer b) Floating – point numbers c) Boolean d) None of the
mentioned
196) 39. What is the order of precedence (highest to lowest) of following operators?
1. &
2. ^
3. ?:
a) 1 -> 2 -> 3
b) 2 -> 1 -> 3
c) 3 -> 2 -> 1
d) 2 -> 3 -> 1
Source: http://www.javaforschool.com/165-program-on-decimal-to-roman-number-
conversion-method-1/#ixzz3GlDxpqlV
289) Answers:
290) Answer 1.
291) 0 [because, the function number ( ) is returning the value of ‘n’, and as we know that
after the execution of the given while loop, the value of ‘n’ becomes 0. Hence, the answer
will be 0.]
292) Answer 2.
293) Lava [because, s1.substring(1,4) gives, “ava”. Hence, “L”+”ava” = Lava]
294) 3 [because, s1.charAt(6) will give ‘o’ and hence, s2.indexOf(‘o’) will give 3.]
295) Java forSchool students [Note: There will be no space between “Java for” and
“School students”]
296) -9 [because, the (ASCII value of J – ASCII value of S) = 74-83 = -9]
297) false [because, “Java for” and “School students” are not equal.]
298) Answer 3.
299) x=3500 [because, first (c>2550?1350:1500) is calculated and then the result is added
to the value of ‘n’. Since, 900 is not greater than 2550, so the result of (c>2550?1350:1500)
is 1500, which is then added to the value of ‘n’ i.e. 2000, and we get the answer as 3500.]
300) y=1350 [because, in this case, first the value of n+c is calculated and then
(n+c>2550?1350:1500) is calculated. Since, n + c = 2000 + 900 = 2900 which is greater
than 2550, so the result of (n+c>2550?1350:1500) is 1350.]
301)
1. String in Java is a?
a) class
b) object
c) variable
d) character array
2. Which of these method of String class is used to obtain character
302) at specified index?
a) char()
b) Charat()
c) charat()
d) charAt()
2. Which of these keywords is used to refer to member of base class
303) from a subclass?
a) upper
b) super
c) this
d) none of the mentioned
304) 4. Which of the below method of the String class can be used to test
305) string equality?
A) equals()
B) isEqual()
C) isequals()
D) equal()
306) 5. Which of the below method of the String class can be used to find
307) the total number of characters in the String?
A) chars()
B) size()
C) len()
D) length()
308) 6. What would be the output of the below code related to String
309) equality?
310) String s = new String("PraBhu");
311) String p = new String("PraBhu");
312) System.out.println(s == p);
A) true
B) false
313) 7. Choose the correct output of the below code about String –
314) Character Equality?
315) Character c = 'A';
316) String s = "A";
317) System.out.println(c.equals(s));
A) true
B) false
318) 8. Method used to take a string as input in Java?
A. next()
B. nextLine()
C. Both A. and B.
D. None of these
319) 9. Array in java is ___.
A. Collection of similar elements
B. Collection of elements of different types
C. The data type of consisting of characters
D. None of these
320) 10. Which of these is the correct method to create an array in java?
A. int[] arr = {1, 3, 5};
B. int[] arr;
C. arr = new int[] {3, 1, 8};
D. int arr[] = {1, 4, 6};
E. All of these
321) 11. Static variables in java are declared as ___.
A. final variables
B. new variables
C. Constants
D. All of these
322) 12. Wrapper class in java is ___.
A. Used to encapsulate primitive data types
B. Declare new classes called wrapper
C. Create a new instance of the class
D. None of these
323) 13. Boxing is ___.
A. Creating new box
B. Creating object
C. Converting primitive type of object instance
D. All of these
324) 14. The correct syntax to import the math library in java is ___.
A. import java.lang.math
B. import math
C. import java.math
D. All of these
325) 15. Which Java method is used to convert an object to string?
A. createString()
B. toString()
C. object.string()
D. newString()
326) 16. Which statement is correct for private member in Java?
A. Access outside the class is allowed
B. Any class can access
C. Declared using private keyword
D. All of these
327) 17. Which keyword is used to inherit classes in Java?
A. extends
B. inheritance
C. isChild
D. None of these
328) 18. What are packages in Java?
A. Methods of a friend class
B. Methods of the main class
C. Way to encapsulate a group of classes, sub-
packages, and
329) interface
330) D. All of these
331) 19. Which of these is a non-access modifier?
A. public
B. private
C. native
D. All of these
332) 20. The trim() method in Java used to ___.
A. Remove the given character
B. Remove the values after the given index
C. Remove leading and trailing spaces
D. None of these
333) 21. Which Java keyword is used to access features of a package?
A. get
B. import
C. extends
D. All of these
334) 22. The result of dividing by 0 in Java is ___.
A. Error
B. Exception
C. Infinite
D. None of these
335) 23. Which among the following best describes encapsulation?
a) It is a way of combining various data members into a single unit
b) It is a way of combining various member functions into a single unit
c) It is a way of combining various data members and member functions
into a single
336) unit which can operate on any data
337) d) It is a way of combining various data members and member functions that operate
on
338) those data members into a single unit
339) 24. 2. If data members are private, what can we do to access them from the class
object?
a) Create public member functions to access those data members
b) Create private member functions to access those data members
c) Create protected member functions to access those data members
d) Private data members can never be accessed from outside the class
340) 4. Which feature can be implemented using encapsulation?
a) Inheritance
b) Abstraction
c) Polymorphism
d) Overloading
341) 9. Which among the following violates the principle of encapsulation almost always?
a) Local variables
b) Global variables
c) Public variables
d) Array variables
342) What package is a part of the wrapper class which is imported by default into all Java
343) programs?
a. java.lang
b. java.awt
c. java.io
d. java.util
344) Write a program in any programming language you to find the first non-repeated
345) character in a given String, for example, if the given String is "Java" then the first
nonrepeated
346) character is "J"