ICSE Class 10 Computer Applications · Competency Practice · 47 solved questions
Exercise
Marks
11 Mark · Multiple Choice Questions
What is the type of error, if any, when two methods have the same method signature?
(a)Runtime error
(b)Logical error
(c)Syntax error
(d)No error
Show SolutionHide Solution↓
Syntax error
Reason — If two methods in the same class have the same method signature (i.e., the same method name and the same parameters), the Java compiler will report a syntax error. This is because Java does not allow duplicate method signatures in the same class as it cannot differentiate which method to call.
21 Mark · Multiple Choice Questions
The advantage/s of user-defined methods are/is:
(i) Reusability (ii) Complexity (iii) Modularity
(a)Only (i)
(b)(ii) and (iii)
(c)Only (iii)
(d)(i) and (iii)
Show SolutionHide Solution↓
(i) and (iii)
Reason — User-defined methods promote reusability by allowing code to be written once and used multiple times, reducing redundancy. They also support modularity by breaking a program into smaller, manageable, and logically separate units, making it easier to understand, maintain, and debug.
31 Mark · Multiple Choice Questions
Parameters which receive the values from the called method are termed as ............... parameters.
(a)actual
(b)formal
(c)reference
(d)class
Show SolutionHide Solution↓
formal
Reason — Parameters that receive values passed from the calling method are called formal parameters. They act as placeholders in the method definition to accept the actual values (actual parameters) during method invocation.
41 Mark · Multiple Choice Questions
Which of the following is a valid method prototype?
(a)public int perform (int a;int b)
(b)public perform (int a, int b)
(c)public int perform (int a, int b)
(d)public perform int (int a, int b)
Show SolutionHide Solution↓
public int perform (int a, int b)
Reason — A valid method prototype in Java must specify the access modifier (public), the return type (int), the method name (perform), and the parameter list enclosed in parentheses with parameters separated by commas. The statement public int perform (int a, int b) correctly follows this syntax.
51 Mark · Multiple Choice Questions
Which of the following is the CORRECT statement to invoke the method with the prototype int display(int a, char ch)?
(a)int m = display('A', 45);
(b)int m = display( );
(c)int m = display(A,45);
(d)int m = display(45,'A');
Show SolutionHide Solution↓
int m = display(45,'A');
Reason — The method display expects two parameters: the first is an int and the second is a char. Among the options, only display(45, 'A') passes the arguments in the correct order and with the correct types—45 as an integer and 'A' as a character literal.
61 Mark · Multiple Choice Questions
Which of the following is the CORRECT java statement to convert the word RESPECT to lowercase?
(a)"RESPECT".tolowercase( );
(b)"RESPECT".toLowerCase( );
(c)toLowerCase("RESPECT");
(d)String.toLowerCase("RESPECT");
Show SolutionHide Solution↓
"RESPECT".toLowerCase( );
Reason — The method to convert a string to lowercase in Java is toLowerCase(), which is called on a string object. It is case-sensitive and must be written exactly as toLowerCase(). Therefore, "RESPECT".toLowerCase() correctly converts the string "RESPECT" to lowercase.
71 Mark · Multiple Choice Questions
Which of the following are Wrapper classes?
(i) Boolean (ii) boolean (iii) character (iv) Character
(a)(i) and (iv)
(b)(ii) and (iv)
(c)(i) and (iii)
(d)(ii) and (iii)
Show SolutionHide Solution↓
(i) and (iv)
Reason — Wrapper classes in Java are object representations of primitive data types. Boolean and Character are wrapper classes corresponding to the primitive types boolean and char, respectively.
81 Mark · Multiple Choice Questions
Conversion of a wrapper class to its corresponding primitive type is known as :
(a)unboxing
(b)autoboxing
(c)type casting
(d)parsing
Show SolutionHide Solution↓
unboxing
Reason — Unboxing is the automatic conversion of an object of a wrapper class (like Integer, Double, etc.) to its corresponding primitive data type (int, double, etc.).
91 Mark · Multiple Choice Questions
The String method, which results only in a positive integer, is :
(a)indexOf
(b)lastIndexOf
(c)compareTo
(d)length
Show SolutionHide Solution↓
length
Reason — The length() method of the String class returns the number of characters in the string as a positive integer. Other methods like indexOf and lastIndexOf return the position of a character or substring, which can be -1 if not found, and compareTo returns an integer that can be positive, negative, or zero depending on lexicographical comparison.
101 Mark · Multiple Choice Questions
The method to convert a String to double is:
(a)String.toDouble()
(b)Double.Parsedouble()
(c)Double.parseDouble(String)
(d)Double.parseDouble()
Show SolutionHide Solution↓
Double.parseDouble(String)
Reason — The method parseDouble in the Double class is used to convert a String representing a numeric value into a primitive double type.
111 Mark · Multiple Choice Questions
The java statement System.out.println(x[x.length]) results in:
(a)logical error
(b)syntax error
(c)run time error
(d)no error
Show SolutionHide Solution↓
run time error
Reason — In Java, arrays are zero-indexed, meaning the valid indices range from 0 to x.length - 1. x.length gives the total number of elements in the array, but accessing x[x.length] tries to access an index outside the valid range, resulting in a ArrayIndexOutOfBoundsException at runtime.
121 Mark · Multiple Choice Questions
Which of the following is a valid array declaration statement to store the Gender of 80 employees [ 'M'-male, 'F'-female, 'T'-transgender ]?
(a)char gender = new char[80];
(b)char gender[] = new char[80];
(c)char gender[80];
(d)char gender[80] = new char[ ];
Show SolutionHide Solution↓
char gender[] = new char[80];
Reason — In Java, arrays must be declared with the type followed by square brackets [] either before or after the variable name. The correct syntax to declare a character array of size 80 is char gender[] = new char[80];.
131 Mark · Multiple Choice Questions
Arrange the following java statements in the correct order of execution to accept values into the array a[]:
(i) a[i]=sc.nextInt( ); (ii) int a[]=new int[10]; (iii) Scanner sc=new Scanner(System.in); (iv) for(i=0;i<10;i++)
(a)(i), (ii), (iii), (iv)
(b)(ii), (iii), (iv), (i)
(c)(iv), (iii), (ii), (i)
(d)(iii), (i), (iv), (ii)
Show SolutionHide Solution↓
(ii), (iii), (iv), (i)
Reason — First, the array a must be declared and initialized (int a[] = new int[10];). Then, the Scanner object sc is created to accept input (Scanner sc = new Scanner(System.in);). Next, a for loop (for(i=0; i < 10; i++)) is used to iterate over the array indices. Inside the loop, values are accepted from the user and stored in the array (a[i] = sc.nextInt();). This sequence ensures proper initialization and input handling.
The statements in the correct order of execution are as follows:
(ii) int a[]=new int[10]; (iii) Scanner sc=new Scanner(System.in); (iv) for(i=0;i<10;i++) (i) a[i]=sc.nextInt( );
141 Mark · Multiple Choice Questions
In the bubble sort technique, during each iteration of the inner loop, two adjacent elements are ............... and ............... .
(i) compared (ii) swapped (iii) selected (iv) deleted
(a)(i) and (ii)
(b)(ii) and (iii)
(c)(iii) and (iv)
(d)(ii) and (iv)
Show SolutionHide Solution↓
(i) and (ii)
Reason — In the bubble sort technique, during each iteration of the inner loop, two adjacent elements are first compared to check their order. If they are found to be in the wrong order, they are swapped to move the larger element towards the end of the list. This process repeats until the array is sorted.
151 Mark · Multiple Choice Questions
What is the highest index of any array with 100 elements?
(a)100
(b)101
(c)99
(d)98
Show SolutionHide Solution↓
99
Reason — Arrays are zero-indexed, meaning the first element of the array is at index 0. Therefore, an array with 100 elements has indices ranging from 0 to 99. Hence, the highest index is 99.
161 Mark · Multiple Choice Questions
Mr. Sanjay is an event manager, he plans and allots duties to each of his subordinates to handle different events. In a program, a task is divided into simple methods. Name the feature used in these contexts.
(a)Complexity
(b)Modularity
(c)Reusability
(d)Monolithic
Show SolutionHide Solution↓
Modularity
Reason — Modularity refers to the practice of dividing a program into separate sub-programs or methods, each handling a specific task. In the context where Mr. Sanjay divides a task into simple methods, the feature being used is modularity.
171 Mark · Multiple Choice Questions
Raj was asked to accept the phone number which has 10 digits, using the appropriate method of Scanner class. Which of the following statement he must choose?
(a)Ob.nextInt()
(b)Ob.nextDouble()
(c)Ob.nextLong()
(d)Ob.next().chatAt(0)
Show SolutionHide Solution↓
Ob.nextLong()
Reason — Raj must use Ob.nextLong() because a 10-digit phone number exceeds the range of the int data type. The long data type can handle larger values, making it suitable for storing 10-digit numbers.
181 Mark · Multiple Choice Questions
Raj wanted to count the number of digits in a given number without using a loop. Which of the following statements is correct to perform the above?
(a)String.valueOf(n).length()
(b)Integer.parseInt(n).length()
(c)n.length()
(d)All the above
Show SolutionHide Solution↓
String.valueOf(n).length()
Reason — The expression String.valueOf(n).length() converts the number n into a string using String.valueOf(n), and then calculates the number of characters (digits) in that string using .length(). This is a valid and loop-free way to count digits in an integer.
191 Mark · Multiple Choice Questions
Sham was asked to encode a string S, by replacing the letter E with #. Select the appropriate statement:
(a)S.replace('#','E')
(b)S.replace('E')
(c)S.replace('E', '#')
(d)S.replace('#')
Show SolutionHide Solution↓
S.replace('E', '#')
Reason — The replace() method in Java is used to replace characters in a string. The correct syntax is S.replace(oldChar, newChar). Since the question asks to replace the letter E with #, we use S.replace('E', '#').
201 Mark · Multiple Choice Questions
When the String m is compared to n, the result obtained is greater than zero. Which of the following is true?
(a)m comes before n in the dictionary.
(b)n comes before m in the dictionary.
(c)m and n are equal.
(d)m and n have the same length.
Show SolutionHide Solution↓
n comes before m in the dictionary.
Reason — If comparing string m to n results in a value greater than zero, it means m is lexicographically greater than n. Hence, n comes before m in the dictionary.
211 Mark · Multiple Choice Questions
Which of the following String methods has integer argument?
(i) length (ii) substring (iii) indexOf (iv) charAt
(a)Only (ii)
(b)(i) and (iv)
(c)(ii) and (iv)
(d)(iii) and (iii)
Show SolutionHide Solution↓
(ii) and (iv)
Reason — The substring(int beginIndex) and charAt(int index) methods both take an integer argument to specify a position within the string. The substring method returns a part of the string starting from the given index, while charAt returns the character at the specified index.
221 Mark · Multiple Choice Questions
Assertion: Property by virtue of which one class acquires the properties of another class is termed as Inheritance.
Reason: Inheritance promotes reusability.
(a)Assertion is true, Reason is false.
(b)Assertion is true, Reason is true.
(c)Assertion is false, Reason is false.
(d)Assertion is false, Reason is true.
Show SolutionHide Solution↓
Assertion is true, Reason is true.
Reason — Inheritance is the property by which one class (subclass) acquires the properties of another class (superclass). It promotes reusability by allowing code to be written once and used by multiple classes.
231 Mark · Multiple Choice Questions
Which of the following is NOT true for polymorphism?
(a)All methods have the same name.
(b)Methods are invoked based on the arguments.
(c)Methods should have the same number and the same type of arguments.
(d)It is a principle of OOPs.
Show SolutionHide Solution↓
Methods should have the same number and the same type of arguments.
Reason — Polymorphism allows methods with the same name to behave differently based on the number or type of arguments passed. Hence, methods do not need to have the same number and same type of arguments.
241 Mark · Multiple Choice Questions
Which of the following is a valid initialisation statement?
(a)int x = "GOOD";
(b)int y = 45.0/2;
(c)int z = (int)'x';
(d)int m = false ;
Show SolutionHide Solution↓
int z = (int)'x';
Reason
int x = "GOOD"; — "GOOD" is a String literal, not an integer. We cannot assign a String to a variable of type int.
int y = 45.0/2; — 45.0 is a double literal, so the result of the division is a double. Assigning a double value to an int without explicit typecasting causes a type mismatch error.
int z = (int)'x'; — This is a valid initialization because the character 'x' is explicitly typecast to an integer, storing its Unicode value in the variable z.
int m = false ; — false is a boolean literal. We cannot assign a boolean value to a variable of type int.
251 Mark · Multiple Choice Questions
Which of the following is a valid statement to print the following sentence:
Raj said "Good morning"
(a)System.out.println("Raj said "Good morning");
(b)System.out.println("Raj said \\Good morning\\);
(c)System.out.println("Raj said \"Good morning\" ");
(d)System.out.println("Raj said Good morning");
Show SolutionHide Solution↓
System.out.println("Raj said \"Good morning\" ");
Reason — The statement System.out.println("Raj said \"Good morning\" "); is valid because it uses the escape sequence \" to include double quotes inside the string. This ensures the output displays exactly as Raj said "Good morning".
261 Mark · Multiple Choice Questions
Which data structure is represented in the below picture?
(i) A two-dimensional array with 2 rows and seven columns. (ii) A one-dimensional array with 14 elements.
(a)Both (i) and (ii)
(b)Only (i)
(c)Only (ii)
(d)None of the (i) and (ii)
Show SolutionHide Solution↓
Only (i)
Reason — A two-dimensional array is a collection of elements arranged in rows and columns. The ice tray shown in the figure looks like a grid with 2 rows and 7 columns, just like a 2D array.
271 Mark · Multiple Choice Questions
What is the type of looping statement depicted in the below picture?
(a)Entry controlled loop
(b)Exit controlled loop
(c)Multiple branching statement
(d)All the above.
Show SolutionHide Solution↓
Entry controlled loop
Reason — An entry controlled loop checks the condition before executing the loop body. In the figure, the condition is evaluated first, and the commands run only if the condition is true, which matches the behaviour of an entry controlled loop like a while loop.
281 Mark · Multiple Choice Questions
What is the process done in the below picture?
(a)Sorting the list in descending order
(b)Searching the character in the list
(c)Sorting the list in ascending order.
(d)None of the above.
Show SolutionHide Solution↓
Sorting the list in ascending order.
Reason — The characters in the list are rearranged from an unordered sequence (B, D, A, C) to an ordered sequence (A, B, C, D) following the alphabetical order, which is called sorting in ascending order.
291 Mark · Multiple Choice Questions
Name the method of search depicted in the below picture.
(a)Binary Search
(b)Selection Sort
(c)Bubble Sort
(d)Linear Search
Show SolutionHide Solution↓
Linear Search
Reason — In Linear Search, each element in the list is checked one by one from the beginning until the required value is found. In the picture, the search starts at the beginning and checks each value one after the other until it finds '6', which matches the method of Linear Search.
301 Mark · Multiple Choice Questions
Name the feature of Java depicted in the below picture.
(a)Encapsulation
(b)Inheritance
(c)Polymorphism
(d)Data abstraction
Show SolutionHide Solution↓
Polymorphism
Reason — Polymorphism means "many forms." In Java, it refers to the ability of a single object to behave differently in different situations. Just like the same person behaves like a customer in a mall, passenger in a bus, student in school, and son at home.
311 Mark · Multiple Choice Questions
Name the data types in order from top, given in the above picture.
(a)int, char, double, String
(b)String, int, char, double
(c)char, double, int, String
(d)int, double, char, String
Show SolutionHide Solution↓
String, int, char, double
Reason
The first value is a sentence in quotes, which is a String.
The second value is 578, a whole number without decimal, so it is of int type.
The third value is \n, which is an escape sequence representing a character, hence char type.
The fourth value is 51.048053, a number with decimals, which is of double type.
321 Mark · Multiple Choice Questions
How many bytes are occupied by the below two-dimensional array?
156
20
154
20
130
20
130
20
162
17.67
161
20
158
17.5
154
20
(a)96 bytes
(b)128 bytes
(c)12 bytes
(d)24 bytes
Show SolutionHide Solution↓
128 bytes
Reason — The given table represents a 4×4 two-dimensional array (4 rows and 4 columns), which means there are 16 elements in total. The values include both integers and decimal numbers, indicating that the array is of double data type (which can store both whole numbers and decimal numbers).
In Java, a double occupies 8 bytes. So, total bytes = 16 elements × 8 bytes = 128 bytes.
331 Mark · Multiple Choice Questions
A girl wanted to calculate the sum of two numbers stored as a and b multiplied by 7. Select the appropriate Java expression.
(a)a + b*7
(b)7*a + b
(c)(a + b)*7
(d)a + 7*b
Show SolutionHide Solution↓
(a + b)*7
Reason — To calculate the sum of two numbers stored as a and b multiplied by 7, we use parentheses to add a and b first, then multiply the result by 7. The correct expression is (a + b)*7.
341 Mark · Multiple Choice Questions
The sum of a[1] and a[3] in the array int a[] = {20, 40, 60, 80, 100} is:
(a)80
(b)100
(c)120
(d)60
Show SolutionHide Solution↓
120
Reason — In the array int a[] = {20, 40, 60, 80, 100}, the index starts from 0.
a[1] refers to the second element: 40
a[3] refers to the fourth element: 80
So, the sum is: 40 + 80 = 120.
351 Mark · Multiple Choice Questions
State which access specifier is less restrictive.
(a)private
(b)protected
(c)default
(d)public
Show SolutionHide Solution↓
public
Reason — The public access specifier is the least restrictive because it allows access to the class members from any other class, anywhere in the program.
361 Mark · Multiple Choice Questions
The AMB hotel gives the amount to be paid by the customer as an integer, which of the following Math method rounds off the bill in decimals to an integer?
(a)Math.round()
(b)Math.pow()
(c)Math.ceil()
(d)Math.abs()
Show SolutionHide Solution↓
Math.round()
Reason — The Math.round() method rounds a decimal number to the nearest integer. It returns the closest whole number, which is suitable for rounding off a bill amount to an integer.
371 Mark · Multiple Choice Questions
Identify which of the following leads to an infinite loop.
(a)for(i = 10; i != 0; i--)
(b)for(i = 3; i <= 30; i += 3)
(c)for(i = 1; i >= 1; i++)
(d)for(i = 1; i >= 0; i--)
Show SolutionHide Solution↓
for(i = 1; i >= 1; i++)
Reason — In the loop for(i = 1; i >= 1; i++), the condition i >= 1 will always be true because i starts at 1 and increases by 1 in each iteration. Since i is always greater than or equal to 1, the loop condition never becomes false. Therefore, the loop runs infinitely, causing an infinite loop.
381 Mark · Multiple Choice Questions
Assertion: A class can have multiple constructors.
Reason: Multiple constructors are defined with same set of arguments.
(a)Assertion is true, Reason is false.
(b)Both assertion and Reason are false.
(c)Both assertion and Reason are true.
(d)Assertion is false, Reason is true.
Show SolutionHide Solution↓
Assertion is true, Reason is false.
Reason — A class can have multiple constructors, this is called constructor overloading. However, multiple constructors cannot have the same set of arguments because that would cause ambiguity. Each constructor must have a different number or type of parameters.
391 Mark · Multiple Choice Questions
Assertion: An array can store elements of different data types.
Reason: An array is a user-defined data type with multiple values of the same data type but a different memory index.
(a)Assertion is true, Reason is false.
(b)Both assertion and Reason are false.
(c)Both assertion and Reason are true.
(d)Assertion is false, Reason is true.
Show SolutionHide Solution↓
Assertion is false, Reason is true.
Reason — An array is a user-defined data type that stores multiple values of the same data type at different memory locations. It cannot store elements of different data types.
401 Mark · Multiple Choice Questions
Which of the following statement is an example for explicit typecasting?
(a)int amount = 45;
(b)int amount = 24*24;;
(c)int amount = Integer.parseInt("45")
(d)int amount = (int)45.75;
Show SolutionHide Solution↓
int amount = (int)45.75;
Reason — Explicit typecasting is when we manually convert one data type to another by specifying the type in parentheses. Here, (int)45.75 converts the double value 45.75 to an int by removing the decimal part.
411 Mark · Multiple Choice Questions
The output of the statement Math.ceil.(89.9) + Math.floor(90.5) is:
(a)0.0
(b)180
(c)180.0
(d)180.4
Show SolutionHide Solution↓
180.0
Reason
Math.ceil(89.9) returns the smallest integer greater than or equal to 89.9, which is 90.0.
Math.floor(90.5) returns the largest integer less than or equal to 90.5, which is 90.0.
Adding them: 90.0 + 90.0 = 180.0
So, the output is 180.0.
421 Mark · Multiple Choice Questions
The output of the statement of "TIGER".indexOf('G') is:
(a)3
(b)2
(c)-1
(d)0
Show SolutionHide Solution↓
2
Reason — The indexOf() method in Java returns the position (index) of the first occurrence of the specified character in the string. In the string "TIGER":
T is at index 0
I is at index 1
G is at index 2
So, "TIGER".indexOf('G') returns 2.
431 Mark · Multiple Choice Questions
Choose the statement which is equivalent to the given:
Reason — The ternary operator condition ? value1 : value2 is used to select one of two values based on a condition. The above if-else statement can be rewritten using the ternary operator inside the println() method as: System.out.println(a > b ? "Honest" : "Sincere");. This statement prints "Honest" if a > b, otherwise it prints "Sincere".
441 Mark · Multiple Choice Questions
The two Java statement are used to check for the equality of the strings "COP" and "cop" are as follows:
"COP".equals("cop")
"COP".equalsIgnoreCase("cop")
The output of the above statements is:
(a)false, true
(b)true, false
(c)false, false
(d)true, true
Show SolutionHide Solution↓
false, true
Reason — In Java:
"COP".equals("cop") checks for exact match, including uppercase and lowercase letters. Since "COP" and "cop" are not exactly the same, it returns false.
"COP".equalsIgnoreCase("cop") checks for equality by ignoring the case of letters. So it treats "COP" and "cop" as equal and returns true.
451 Mark · Multiple Choice Questions
The output of the java statement "SOLDIER".compareTo("SOLUTE"); is
(a)-4
(b)-17
(c)17
(d)0
Show SolutionHide Solution↓
-17
Reason — The compareTo() method in Java compares two strings lexicographically using the Unicode values.
Let's compare "SOLDIER" and "SOLUTE":
The first three letters S, O, L are the same in both strings.
The 4th letter in "SOLDIER" is 'D' and in "SOLUTE" it is 'U'.
Unicode of 'D' = 68, Unicode of 'U' = 85.
68 − 85 = -17
So, the output is -17.
461 Mark · Multiple Choice Questions
Arrange the following in the descending order of number of bytes occupied.
(i) char x[20] (ii) int a[4][2] (iii) double b[6]
(a)(iii), (ii), (i)
(b)(iii), (i), (ii)
(c)(ii), (iii), (i)
(d)(i), (ii), (iii)
Show SolutionHide Solution↓
(iii), (i), (ii)
Reason — To find the number of bytes occupied by each array, we multiply the number of elements by the size of each data type:
(i) char x[20] — 20 elements * 2 bytes = 40 bytes (ii) int a[4][2] — 4 * 2 = 8 elements * 4 bytes = 32 bytes (iii) double b[6] — 6 elements * 8 bytes = 48 bytes
Now arranging in descending order: (iii) 48 bytes, (i) 40 bytes, (ii) 32 bytes
471 Mark · Multiple Choice Questions
Sam performs bubble sort on the following array to organise the elements in ascending order: {5, 1, 2, 3}
After the first comparison the array is: {1, 5, 2, 3}
What would be the array after the next comparison?
(a){1, 2, 5, 3}
(b){1, 5, 3, 2}
(c){1, 3, 5, 2}
(d){1, 3, 2, 5}
Show SolutionHide Solution↓
{1, 2, 5, 3}
Reason — In Bubble Sort, adjacent elements are compared and swapped if they are in the wrong order.
Original array: {5, 1, 2, 3} After the first comparison (compare 5 and 1): Since 5 > 1, they are swapped → {1, 5, 2, 3}
Next comparison (second comparison): Compare 5 and 2. Since 5 > 2, they are swapped → {1, 2, 5, 3}
So, after the next comparison, the array becomes {1, 2, 5, 3}.