ICSE · Class 10 · Computer Applications
Class 10 Library Classes Mock Test (ICSE)
6 practice questions from Library Classes, in the style of your board paper, each with a worked answer and the marks for every step. Then take a full chapter test on paper, snap the pages and get every step marked.
Topics in Library Classes
- Wrapper classes
- Autoboxing and unboxing
- Character class methods
- Parsing strings to numbers with Integer.parseInt and Double.parseDouble
- Packages and import
Library Classes practice questions with answers
- Q1Multiple choice1 markWhich method is used to convert a String representation of a decimal number into a primitive double value?
- (a)Double.parseDouble()
- (b)Float.parseFloat()
- (c)Integer.parseInt()
- (d)Double.valueOf()
Show answer and step marks
- Correct option: (a) Double.parseDouble()+1
Answer: (a) - Q2Multiple choice1 markWhat is autoboxing in Java?
- (a)Automatic conversion of a wrapper class object to its primitive type
- (b)Manual conversion using the valueOf() method
- (c)Automatic conversion of a primitive type to its corresponding wrapper class object
- (d)Converting a String to an integer using parseInt()
Show answer and step marks
- Correct option: (c) Automatic conversion of a primitive type to its corresponding wrapper class object+1
Answer: (c) - Q3Multiple choice1 markWhat will be the output of the following statement? `System.out.println(Character.isLetter('9'));`
- (a)9
- (b)false
- (c)true
- (d)Compilation error
Show answer and step marks
- Correct option: (b) false+1
Answer: (b) - Q4Short answer2 marksWhat is a wrapper class in Java? State the primitive data types corresponding to the `Integer` and `Character` wrapper classes.
Show answer and step marks
- A wrapper class is a class that wraps (encapsulates) a value of a primitive data type into an object.+1
- `Integer` corresponds to `int`.+0.5
- `Character` corresponds to `char`.+0.5
Answer: A wrapper class wraps a primitive type into an object; Integer corresponds to int and Character corresponds to char. - Q5Long answer4 marksWrite a Java program to accept an integer number using the Scanner class. Store this value in a primitive int variable, perform autoboxing to store it in an Integer wrapper object, unbox it to perform arithmetic addition of , and finally print the updated value using System.out.println.
Show answer and step marks
- `import java.util.Scanner;` with the class and `main` method declared correctly.+1
- `Scanner` object created and the integer read into a primitive `int` variable with `nextInt()`.+1
- Autoboxing: assigning the primitive to a wrapper object, `Integer boxed = n;`.+0.5
- Unboxing: using the wrapper object in arithmetic, `int updated = boxed + 5;`.+0.5
- Printing the updated value with `System.out.println` and a message.+1
Answer: import java.util.Scanner; class BoxingDemo { public static void main(String args[]) { Scanner sc = new Scanner(System.in); System.out.print("Enter an integer: "); int n = sc.nextInt(); Integer boxed = n; int updated = boxed + 5; System.out.println("Updated value = " + updated); } } Here Integer boxed = n; is autoboxing and boxed + 5 unboxes boxed to an int. - Q6Long answer4 marksWrite a Java program using the `Scanner` class to accept integer numbers from the user and store them in an `Integer` array, thereby demonstrating **autoboxing**. Then, traverse the array to compute the sum of all the numbers and find the maximum number, thereby demonstrating **unboxing**. Finally, display the calculated sum and the maximum number.
Show answer and step marks
- `import java.util.Scanner;`, the class and `main` declared, and a `Scanner` object created.+0.5
- `Integer arr[] = new Integer[10];` filled in a loop with `arr[i] = sc.nextInt();`, the `int` values being autoboxed.+1
- Sum: `sum = sum + arr[i];` in a loop, each `Integer` unboxed to `int`.+0.5
- Maximum: `max` initialised to `arr[0]` and replaced whenever `arr[i] > max`.+1
- Display of the sum.+0.5
- Display of the maximum.+0.5
Answer: import java.util.Scanner; class WrapperArray { public static void main(String args[]) { Scanner sc = new Scanner(System.in); Integer arr[] = new Integer[10]; System.out.println("Enter 10 integers:"); for (int i = 0; i < 10; i++) { arr[i] = sc.nextInt(); } int sum = 0; int max = arr[0]; for (int i = 0; i < 10; i++) { sum = sum + arr[i]; if (arr[i] > max) max = arr[i]; } System.out.println("Sum = " + sum); System.out.println("Maximum = " + max); } }
Take a full Library Classes test
PrepitUp writes a fresh paper on this chapter at the length you pick. Write it on paper with a timer, photograph the pages, and see the marks for every step and what to practise next.
- 15 min10 marks
- 30 min20 marks
- 1.5 hr40 marks
- 3 hr80 marks
Get your Library Classes answers marked
Sign in, pick this chapter and a length, write the test on paper and get every step marked.
Sign in to take this test