0% found this document useful (0 votes)
17 views

Objective type Question Answer

Uploaded by

macroff9932.ac
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Objective type Question Answer

Uploaded by

macroff9932.ac
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

Objective type Question Answer

Class – X , ICSE
Prepared & Guided By : Souvik Chakraborty , M.Sc(C.S) , B.Ed

1. Basics

Q1.

Assertion (A): Java is platform-independent.


Reason (R): Java code is compiled to bytecode, which can run on any platform
with a JVM.

Answer:

 A is true, R is true, and R is the correct explanation of A.

Q2.

Assertion (A): Java supports multiple inheritance using classes.


Reason (R): Java provides interfaces to achieve multiple inheritance.

Answer:

 A is false, R is true.
(Explanation: Java does not support multiple inheritance with classes
directly, but it can be achieved through interfaces.)

Q3.

Assertion (A): Java uses garbage collection to manage memory.


Reason (R): The System.gc() method guarantees the execution of the garbage
collector.

Answer:

By : Souvik_Chakraborty_M.Sc_CS 1/17
 A is true, R is false.
(Explanation: The System.gc() method only suggests the JVM to run the
garbage collector; it does not guarantee it.)

Q4.

Assertion (A): Java does not support operator overloading.


Reason (R): Java’s simplicity is maintained by restricting operator overloading.

Answer:

 A is true, R is true, and R is the correct explanation of A.

Q5.

Assertion (A): Java’s main() method must be declared public.


Reason (R): The main() method is the entry point for the JVM to start program
execution.

Answer:

 A is true, R is true, and R is the correct explanation of A.

2. Loops

Q1.

Assertion (A): The while loop is an entry-controlled loop.


Reason (R): The condition is checked before the loop body is executed in a while
loop.

Answer:

 A is true, R is true, and R is the correct explanation of A.

By : Souvik_Chakraborty_M.Sc_CS 2/17
Q2.

Assertion (A): The for loop is useful for iterating over an array.
Reason (R): The for loop can have an initialization, condition, and
increment/decrement in a single line.

Answer:

 A is true, R is true, and R is the correct explanation of A.

Q3.

Assertion (A): A break statement terminates the nearest enclosing loop.


Reason (R): The break statement stops loop execution and transfers control to the
statement after the loop.

Answer:

 A is true, R is true, and R is the correct explanation of A.

Q4.

Assertion (A): The continue statement in a loop skips the current iteration.
Reason (R): The continue statement transfers control to the beginning of the loop.

Answer:

 A is true, R is true, and R is the correct explanation of A.

Q5.

Assertion (A): A do-while loop checks the condition at the start of the loop.
Reason (R): A do-while loop is suitable for executing the body at least once
regardless of the condition.

Answer:
By : Souvik_Chakraborty_M.Sc_CS 3/17
 A is false, R is true.
(Explanation: The condition in a do-while loop is checked after the loop
body runs.)

3. Arrays

Q1.

Assertion (A): The elements of an array are stored in contiguous memory


locations.
Reason (R): Accessing elements of an array using indices ensures fast retrieval.

Answer:

 A is true, R is true, and R is the correct explanation of A.

Q2.

Assertion (A): The length of an array can be changed after its declaration.
Reason (R): Arrays in Java are fixed in size once created.

Answer:

 A is false, R is true.
(Explanation: Arrays in Java have a fixed size, and their length cannot be
modified after declaration.)

Q3.

Assertion (A): The ArrayIndexOutOfBoundsException is thrown if an invalid


index is accessed.
Reason (R): Java checks array bounds at runtime to ensure memory safety.

Answer:

 A is true, R is true, and R is the correct explanation of A.


By : Souvik_Chakraborty_M.Sc_CS 4/17
Q4.

Assertion (A): Arrays can store both primitive types and objects in Java.
Reason (R): Arrays are a part of Java’s collection framework.

Answer:

 A is true, R is false.
(Explanation: Arrays are not a part of the Java collection framework; they
are part of the core language.)

Q5.

Assertion (A): An array can be passed as an argument to a method.


Reason (R): Passing an array to a method sends a reference to the original array.

Answer:

 A is true, R is true, and R is the correct explanation of A.

4. Strings

Q1.

Assertion (A): Strings in Java are stored in the heap memory.


Reason (R): The String class is immutable, and string literals are stored in the
string pool.

Answer:

 A is true, R is true, but R is not the correct explanation of A.

By : Souvik_Chakraborty_M.Sc_CS 5/17
Q2.

Assertion (A): The == operator checks the reference equality of strings.


Reason (R): The equals() method in Java checks the content equality of strings.

Answer:

 A is true, R is true, and R is the correct explanation of A.

Q3.

Assertion (A): The StringBuilder class is preferred for string concatenation in a


loop.
Reason (R): The StringBuilder class is mutable and avoids creating multiple
objects.

Answer:

 A is true, R is true, and R is the correct explanation of A.

Q4.

Assertion (A): The substring() method in Java returns a new string.


Reason (R): The String class in Java creates new objects for string manipulation.

Answer:

 A is true, R is true, and R is the correct explanation of A.

Q5.

Assertion (A): Strings are a primitive data type in Java.


Reason (R): Java provides wrapper classes for primitive data types.

Answer:

By : Souvik_Chakraborty_M.Sc_CS 6/17
 A is false, R is true.
(Explanation: Strings are not primitive; they are objects of the String
class.)

5. Methods

Q1.

Assertion (A): A method in Java can have multiple return statements.


Reason (R): The control of a method returns to the calling function after a return
statement.

Answer:

 A is true, R is true, and R is the correct explanation of A.

Q2.

Assertion (A): Methods can have the same name in Java.


Reason (R): Method overloading allows defining methods with the same name but
different parameter lists.

Answer:

 A is true, R is true, and R is the correct explanation of A.

Q3.

Assertion (A): A method declared as static can be called without creating an


object.
Reason (R): Static methods belong to the class, not an instance of the class.

Answer:

 A is true, R is true, and R is the correct explanation of A.

By : Souvik_Chakraborty_M.Sc_CS 7/17
Q4.

Assertion (A): A method can be recursive in Java.


Reason (R): Recursive methods call themselves to solve smaller sub-problems.

Answer:

 A is true, R is true, and R is the correct explanation of A.

Q5.

Assertion (A): Methods can only return void in Java.


Reason (R): The return type of a method defines what type of value it returns.

Answer:

 A is false, R is true.
(Explanation: Methods can return various data types, not just void.)

6. Constructors

Q1.

Assertion (A): Constructors do not have a return type.


Reason (R): Constructors are used for object initialization, not for returning
values.

Answer:

 A is true, R is true, and R is the correct explanation of A.

By : Souvik_Chakraborty_M.Sc_CS 8/17
Q2.

Assertion (A): If no constructor is defined in a class, Java provides a default


constructor.
Reason (R): The default constructor initializes object fields with default values.

Answer:

 A is true, R is true, and R is the correct explanation of A.

Q3.

Assertion (A): Constructors can be overloaded.


Reason (R): Constructor overloading allows creating multiple constructors with
different parameters.

Answer:

 A is true, R is true, and R is the correct explanation of A.

Q4.

Assertion (A): A constructor can be static.


Reason (R): Constructors are special methods called when an object is created,
and static methods can be accessed without an instance.

Answer:

 A is false, R is false.
(Explanation: Constructors cannot be static.)

Q5.

Assertion (A): Constructors cannot be inherited.


Reason (R): Constructors are not methods and are only called during the
instantiation of an object.
By : Souvik_Chakraborty_M.Sc_CS 9/17
Answer:

 A is true, R is true, and R is the correct explanation of A.

7. Method Overloading

Q1.

Assertion (A): Method overloading allows multiple methods with the same name
in a class.
Reason (R): The methods must differ in their parameter type, number, or order.

Answer:

 A is true, R is true, and R is the correct explanation of A.

Q2.

Assertion (A): The return type of overloaded methods must be different.


Reason (R): The Java compiler uses return type to differentiate overloaded
methods.

Answer:

 A is false, R is false.
(Explanation: Overloaded methods cannot be differentiated by return type
alone.)

Q3.

Assertion (A): Method overloading improves code readability.


Reason (R): Similar methods can be grouped under the same name with different
parameters.

Answer:

By : Souvik_Chakraborty_M.Sc_CS 10/17
 A is true, R is true, and R is the correct explanation of A.

Q4.

Assertion (A): Method overloading can only be done within the same class.
Reason (R): Method overriding is used to redefine methods in subclasses.

Answer:

 A is true, R is true, but R is not the correct explanation of A.


(Explanation: Method overloading can indeed only be done within the same
class.)

Q5.

Assertion (A): An overloaded method can have a static modifier.


Reason (R): Method overloading can be applied to both static and instance
methods.

Answer:

 A is true, R is true, and R is the correct explanation of A.

1. Arrays

Q1.
class ArrayExample {
public static void main(String[] args) {
int[] arr = {10, 20, 30, 40, 50};
int i = 1, j = 3, sum = 0;

sum += arr[i++] + arr[--j];


sum += arr[i]++ + arr[j--];
sum += arr[++i] + arr[j];
By : Souvik_Chakraborty_M.Sc_CS 11/17
System.out.println("Sum: " + sum);
}
}

Output:
Sum: 145

Explanation:

1. arr[i++] + arr[--j]: i = 1, so arr[i++] = 20; --j = 2, so arr[2] = 30.


Sum becomes 20 + 30 = 50.
o Now i = 2, j = 2.
2. arr[i]++ + arr[j--]: arr[2]++ = 30 (post-increment) and arr[2] = 30.
Sum becomes 50 + 30 + 30 = 110.
o Now i = 2, j = 1.
3. arr[++i] + arr[j]: ++i = 3, so arr[3] = 40; arr[1] = 20. Sum becomes
110 + 40 + 20 = 145.

Q2.
class ArrayManipulation {
public static void main(String[] args) {
int[] a = {5, 10, 15, 20, 25};
int x = 0, y = 4, diff = 0;

diff = a[y--] - a[++x];


diff += a[x++] + a[--y];
diff -= a[y--] - a[--x];

System.out.println("Difference: " + diff);


}
}

Output:
Difference: 15

Explanation:

1. a[y--] - a[++x]: a[4] = 25, ++x = 1, so a[1] = 10. Difference becomes


25 - 10 = 15.
o Now y = 3, x = 1.

By : Souvik_Chakraborty_M.Sc_CS 12/17
2. a[x++] + a[--y]: a[1] = 10 (post-increment), --y = 2, so a[2] = 15.
Difference becomes 15 + 10 + 15 = 40.
o Now x = 2, y = 2.
3. a[y--] - a[--x]: a[2] = 15, --x = 1, so a[1] = 10. Difference becomes
40 - (15 - 10) = 15.

Q3.
class ArrayRotation {
public static void main(String[] args) {
int[] arr = {1, 2, 3, 4, 5};
int n = arr.length;

for (int i = 0; i < n; i++) {


int temp = arr[0];
for (int j = 0; j < n - 1; j++) {
arr[j] = arr[j + 1];
}
arr[n - 1] = temp;

// Printing the array after each rotation


for (int k = 0; k < n; k++) {
System.out.print(arr[k] + " ");
}
System.out.println();
}
}
}

Output:
Copy code
2 3 4 5 1
3 4 5 1 2
4 5 1 2 3
5 1 2 3 4
1 2 3 4 5

Explanation: The program performs a left rotation on the array for n iterations.
Each iteration moves the first element to the end while shifting all others to the
left.

By : Souvik_Chakraborty_M.Sc_CS 13/17
Q4.
class ArraySum {
public static void main(String[] args) {
int[][] arr = {
{1, 2, 3},
{4, 5, 6},
{7, 8, 9}
};

int rowSum = 0, colSum = 0;

for (int i = 0; i < arr.length; i++) {


rowSum += arr[i][i];
colSum += arr[i][arr.length - i - 1];
}

System.out.println("Diagonal 1 Sum: " + rowSum);


System.out.println("Diagonal 2 Sum: " + colSum);
}
}

Output:
Diagonal 1 Sum: 15
Diagonal 2 Sum: 15

Explanation:

 Diagonal 1: 1 + 5 + 9 = 15
 Diagonal 2: 3 + 5 + 7 = 15.

2. Strings

Q1.
class StringExample {
public static void main(String[] args) {
String s = "ICSE";
s = s.concat(" 2024").toLowerCase();
s = s.substring(0, 6);

StringBuilder sb = new StringBuilder(s);


sb.reverse();
s = sb.toString();

System.out.println(s);
By : Souvik_Chakraborty_M.Sc_CS 14/17
}
}

Output:
420 202

Explanation:

1. s.concat(" 2024") → ICSE 2024.


2. .toLowerCase() → icse 2024.
3. .substring(0, 6) → icse 2.
4. StringBuilder.reverse() → 420 202.

Q2.
class PalindromeCheck {
public static void main(String[] args) {
String str = "MADAM";
String rev = "";

for (int i = str.length() - 1; i >= 0; i--) {


rev += str.charAt(i);
}

if (str.equals(rev)) {
System.out.println("Palindrome");
} else {
System.out.println("Not a Palindrome");
}
}
}

Output:
Palindrome

Explanation: The input string MADAM matches its reverse, so it is a palindrome.

Q3.
class SubstringCount {
public static void main(String[] args) {
String s = "ICSE ICSE ICSE";

By : Souvik_Chakraborty_M.Sc_CS 15/17
String word = "ICSE";
int count = 0;

for (int i = 0; i <= s.length() - word.length(); i++) {


if (s.substring(i, i + word.length()).equals(word)) {
count++;
}
}

System.out.println("Count: " + count);


}
}

Output:
Count: 3

Explanation: The program iterates over the string and counts non-overlapping
occurrences of "ICSE".

Q4.
class ReplaceVowels {
public static void main(String[] args) {
String s = "ICSE 2024";
String result = "";

for (int i = 0; i < s.length(); i++) {


char c = s.charAt(i);
if ("AEIOUaeiou".indexOf(c) != -1) {
result += '*';
} else {
result += c;
}
}

System.out.println(result);
}
}

Output:
*CS* 2024

Explanation:
The vowels (I, E) are replaced with *.

By : Souvik_Chakraborty_M.Sc_CS 16/17
Q5.
class AnagramCheck {
public static void main(String[] args) {
String str1 = "listen";
String str2 = "silent";

char[] arr1 = str1.toCharArray();


char[] arr2 = str2.toCharArray();

java.util.Arrays.sort(arr1);
java.util.Arrays.sort(arr2);

if (java.util.Arrays.equals(arr1, arr2)) {
System.out.println("Anagrams");
} else {
System.out.println("Not Anagrams");
}
}
}

Output:
Anagrams

Explanation:
Sorting the characters of both strings and comparing them shows that they are
anagrams.

XXXXX END XXXXX

Best Wish For your Pre-Board Examination

By : Souvik_Chakraborty_M.Sc_CS 17/17

You might also like