Docsity

Computer JAVA - MCQ bank Class 10 ICSE, Quizzes of Computer science

Toggle sidebar
bg1
public class Main {
public static void main(String[] a) {
int score = 50;
System.out.println("MCQ");
}
}
ICSE · CLASS 10 · COMPUTER APPLICATIONS
JAVA
50 MCQs
FULL ICSE SYLLABUS
Code-based multiple choice questions with the answer and a
one-line explanation right below every question.
50 MCQs Code Snippets Answer + Reason Full Syllabus
Compiled by Anirban Giri
Tap the next page to jump to any section.
// attempt first, then read the answer
MCQ Bank by Anirban Giri
pf3
pf4
pf5
pf8
pf9
pfa

Partial preview of the text

Download Computer JAVA - MCQ bank Class 10 ICSE and more Quizzes Computer science in PDF only on Docsity!

public class Main { public static void main(String[] a) { int score = 50; System.out.println("MCQ"); } }

ICSE · CLASS 10 · COMPUTER APPLICATIONS

JAVA

50 MCQs

FULL ICSE SYLLABUS

Code-based multiple choice questions with the answer and a

one-line explanation right below every question.

50 MCQs Code Snippets Answer + Reason Full Syllabus

Compiled by Anirban Giri

Tap the next page to jump to any section.

// attempt first, then read the answer

MCQ Bank by Anirban Giri

Contents

Tap a section to jump to it. Every page has a CONTENTS link at the bottom right.

1 Java Basics, Tokens & Data Types (Q1 to Q6) p. 3

2 Operators, Math Library & Input (Q7 to Q12) p. 4

3 Control Statements & Loops (Q13 to Q18) p. 5

4 Classes, Objects & Encapsulation (Q19 to Q24) p. 6

5 Constructors & Methods (Q25 to Q31) p. 7

6 Library Classes & Wrapper Classes (Q32 to Q36) p. 8

7 Arrays (Q37 to Q43) p. 8

8 String Handling (Q44 to Q50) p. 9

Syllabus map: where each ICSE unit is covered

ICSE Class 10 unit Covered in Revision of Class IX: tokens, data types, operators, input, Math library, conditions, loops Sections 1, 2 and 3

Class as the basis of computation, objects, encapsulation, access specifiers Section 4 Constructors and user-defined methods (overloading, pure and impure, pass by value) Section 5

Library classes: wrapper classes, autoboxing, Character and Integer methods Section 6 Arrays: single and double dimensional, linear and binary search, bubble and selection sort Section 7 String handling and String methods Section 8

Quick reference

Type Size Default Example byte 1 byte 0 byte b = 10;

short 2 bytes 0 short s = 100; int 4 bytes 0 int n = 25; long 8 bytes 0L long l = 5000L; float 4 bytes 0.0f float f = 2.5f; double 8 bytes 0.0 double d = 3.14;

char 2 bytes '\u0000' char c = 'A'; boolean true / false false boolean ok = true;

MCQ Bank by Anirban Giri

Which of the following is NOT a token in Java?

(a) comment (b) keyword (c) literal (d) operator

Ans. (a) Comments are ignored by the compiler, so they are not tokens.

2 Operators, Math Library & Input

What is the output of the following code?

int x = 5; x += x++ + ++x; System.out.println(x);

(a) 12 (b) 16 (c) 17 (d) 18

Ans. (c) x += e means 5 + (5 + 7): x++ gives 5 (x becomes 6), then ++x makes it 7.

What is the output of the following statement?

System.out.println(10 + 20 + "Java" + 10 + 20);

(a) 30Java30 (b) Java (c) 1020Java1020 (d) 30Java

Ans. (d) 10 + 20 is added first; once a String appears, + concatenates: 30Java1020.

What does Math.round(4.5) return?

(a) 4.0 (b) 5. (c) 4 (d) 5

Ans. (d) round() rounds .5 up and returns a long, so the result is 5.

What does Math.ceil(7.2) return?

(a) 7 (b) 8 (c) 7.0 (d) 8.

Ans. (d) ceil() gives the smallest whole number not less than the value, as a double.

Which Scanner method reads an entire line of text?

(a) nextLine() (b) next() (c) nextInt() (d) readLine()

Ans. (a) nextLine() reads the whole line including spaces.

What does Math.pow(2, 3) return?

(a) 6 (b) 8 (c) 8.0 (d) 9.

Ans. (c) pow() always returns a double, so the result is 8.0.

MCQ Bank by Anirban Giri

3 Control Statements & Loops

What is the output of the following code?

for (int i = 1; i <= 3; i++) System.out.print(i * i + " ");

(a) 1 2 3 (b) 1 4 9 (c) 2 4 6 (d) 1 8 27

Ans. (b) It prints the squares of 1, 2 and 3.

How many times does the loop body execute?

int i = 10; while (i > 0) { i -= 3; }

(a) 3 (b) 4 (c) 5 (d) 10

Ans. (b) The body runs with i = 10, 7, 4 and 1 (i then becomes -2), so 4 times.

Which of the following is an exit-controlled loop?

(a) for (b) while (c) do-while (d) none of these

Ans. (c) do-while checks the condition after the body, so it runs at least once.

What is the output of the following code?

int n = 2; switch (n) { case 1: System.out.print("A"); case 2: System.out.print("B"); case 3: System.out.print("C"); break; default: System.out.print("D"); }

(a) BCD (b) C (c) B (d) BC

Ans. (d) There is no break after case 2, so control falls through to case 3, where break stops it.

What is the output of the following code?

for (int i = 1; i <= 5; i++) { if (i == 3) continue; System.out.print(i); }

(a) 1245 (b) 12345 (c) 12 (d) 45

Ans. (a) continue skips only the rest of the iteration where i is 3.

MCQ Bank by Anirban Giri

5 Constructors & Methods

A constructor must have the same name as:

(a) the method (b) the class (c) the object (d) the package

Ans. (b) The constructor name must match the class name.

What is the return type of a constructor?

(a) void (b) int (c) it has no return type (not even void) (d) String

Ans. (c) A constructor never declares a return type.

Defining several constructors with different parameter lists in a class is called:

(a) constructor overriding (b) recursion (c) encapsulation (d) constructor overloading

Ans. (d) Different parameter lists make them overloaded constructors.

What is the output of the following code?

void change(int x) { x = x + 10; } // in main: int n = 5; change(n); System.out.println(n);

(a) 5 (b) 10 (c) 15 (d) error

Ans. (a) Primitive arguments are passed by value, so n is not changed.

Method overloading means methods with the same name but:

(a) different class names (b) different parameter lists (c) the same parameter lists (d) different return types only

Ans. (b) The number, type or order of parameters must differ (return type alone is not enough).

A method that does not change the state of the object is called:

(a) impure method (b) constructor (c) pure method (d) static block

Ans. (c) A pure method (accessor) only reads the object's data.

If a class defines no constructor, Java provides:

(a) a compile-time error (b) a copy constructor (c) a parameterised constructor (d) a default constructor with no parameters

Ans. (d) The compiler adds a no-argument default constructor.

MCQ Bank by Anirban Giri

6 Library Classes & Wrapper Classes

What is the wrapper class of the primitive type char?

(a) Character (b) Char (c) character (d) String

Ans. (a) The wrapper for char is Character.

Which statement converts the String "25" into an int?

(a) int n = "25"; (b) int n = Integer.parseInt("25"); (c) int n = Integer.toString("25"); (d) int n = String.parseInt("25");

Ans. (b) Integer.parseInt() converts a numeric String to an int.

Automatic conversion of a primitive into its wrapper object (e.g. Integer x = 5;) is called:

(a) casting (b) unboxing (c) autoboxing (d) parsing

Ans. (c) Autoboxing wraps the primitive automatically; the reverse is unboxing.

What does Character.isLetter('7') return?

(a) true (b) error (c) 7 (d) false

Ans. (d) '7' is a digit, not a letter.

What does Integer.toString(25) return?

(a) the String "25" (b) the double 25. (c) the int 25 (d) an error

Ans. (a) It converts the number into a String.

7 Arrays

To find the number of elements of an array a, we use:

(a) a.length() (b) a.length (c) a.size() (d) length(a)

Ans. (b) length is a property of an array, written without brackets.

What is the default value of each element of int a[] = new int[3];?

(a) garbage value (b) null (c) 0 (d) -

Ans. (c) Elements of a numeric array start as 0.

MCQ Bank by Anirban Giri

What does "banana".indexOf('n') return?

(a) 3 (b) 4 (c) 1 (d) 2

Ans. (d) The first 'n' is at index 2 (b-a-n).

What does "apple".compareTo("apricot") return?

(a) -2 (b) 2 (c) 0 (d) 1

Ans. (a) The first difference is at index 2: 'p' (112) - 'r' (114) = -2.

Which method compares two Strings ignoring case?

(a) equals() (b) equalsIgnoreCase() (c) compareTo() (d) ==

Ans. (b) equalsIgnoreCase() treats upper and lower case letters as equal.

What is the output of the following code?

String s = "Java"; s.concat(" Programming"); System.out.println(s);

(a) Java (b) Java Programming (c) Programming (d) error

Ans. (a) Strings are immutable: concat() returns a new String that was not stored.

Score yourself

Score Result

45 to 50 Excellent: you are board-ready

35 to 44 Very good: revise the sections where you slipped 25 to 34 Good start: re-read the notes and retry the wrong questions

Below 25 Revise the basics and try again

MCQ Bank by Anirban Giri Keep coding, and all the best for your boards! · MCQ Bank by Anirban Giri