
Q1
Q1 Which of these is not a feature of Java?
Object-oriented
Platform-independent
Compiled
Interpreted language
Q2
Q2 What is the purpose of the PATH environment variable in Java?
To locate Java libraries
To store Java bytecode
To locate the Java compiler
To optimize Java code
Q3
Q3 In Java, how should class names be written?
camelCase
snake_case
PascalCase
kebab-case
Q4
Q4 Which of these is a single-line comment in Java?
Q5
Q5 What is the default value of a boolean variable in Java?
true
false
0
null
Q6
Q6 What is the result of this operation in Java:
(int)(7.9)?
7
7.9
8
Syntax Error
Q7
Q7 Which keyword is used to define a constant variable in Java?
final
static
const
immutable
Q8
Q8 What is the range of the short data type in Java?
-32768 to 32767
-128 to 127
-2147483648 to 2147483647
0 to 65535
Q9
Q9 What will be the output of the following code snippet:
int a = 10;
int b = 20;
System.out.println(a + b);
10
20
30
Error
Q10
Q10 What does the following Java code print?
int x = 5;
int y = x++;
System.out.println(y);
5
6
Syntax Error
None of the above
Q11
Q11 Determine the output:
SET num = 8
IF num MOD 2 = 0
THEN PRINT "Even"
ELSE
PRINT "Odd"
Even
Odd
Error
No output
Q12
Q12 Identify the error in this code:
int[] nums = new int[2]; nums[0] = 1; nums[1] = 2; nums[2] = 3;
Array index out of bounds
Incorrect array declaration
No error
Syntax error
Q13
Q13 Which control structure is used to execute a block of code multiple times?
if
switch-case
for
try-catch
Q14
Q14 In a 'switch-case' statement, what is the role of the 'break' keyword?
To pause the execution
To terminate the case block
To skip to the next case
To repeat the case block
Q15
Q15 What will the following loop print?
for(int i = 0;
i < 3;
i++){
System.out.println(i);
}
0 1 2
1 2 3
0 1 2 3
None
Q16
Q16 What will this pseudocode output?
SET count = 5 DO PRINT count COUNTDOWN count
5 4 3 2 1
5
1 2 3 4 5
None
Q17
Q17 Identify the error in this code:
for(int i=0;
i<=5;
i++) {
System.out.println(i);
}
System.out.println(i);
Syntax error outside loop
No error
Variable i not accessible outside loop
Infinite loop
Q18
Q18 Find the error in this code:
int num = 1;
do{
System.out.println(num);
num++;
}
while(num <= 3);
System.out.println(num);
Infinite loop
Syntax error
Prints wrong values
No error
Q19
Q19 In Java, what is the default value of an array of integers?
0
null
1
-1
Q20
Q20 Which of these is not a valid way to instantiate an array in Java?
int[] arr = new int[5];
int arr[] = new int[5];
int arr[] = {1, 2, 3, 4, 5};
int arr[] = int[5];
Q21
Q21 What will the following code output:
int[] arr = {1, 2, 3};
for(int num : arr) {
System.out.println(num);
}
1 2 3
123
Error
None
Q22
Q22 What will be the result of executing this code snippet?
String[] names = {"Java", "Python", "C++"};
System.out.println(names[1].length());
4
5
6
Error
Q23
Q23 What will this pseudocode output?
SET arr = [1, 2, 3] FOR EACH num IN arr PRINT num
1 2 3
123
Error
None
Q24
Q24 What will be the result of this pseudocode?
SET matrix = [[1, 2], [3, 4]]
PRINT matrix[0][1]
1
2
3
4
Q25
Q25 Identify the issue in this code snippet:
int[] numbers = new int[5];
for(int i = 0;
i <= numbers.length;
i++) {
System.out.println(numbers[i]);
}
Out of bounds array access
No issue
Syntax error
Logic error
Q26
Q26 Find the error in this Java code:
int[][] matrix = new int[2][2];
matrix[0][0] = 1;
matrix[0][1] = 2;
matrix[1][0] = 3;
System.out.println(matrix[1][1]);
Prints incorrect value
No error
Syntax error
Missing initialization for matrix[1][1]
Q27
Q27 Identify the flaw in this Java code:
char[] chars = new char[-1];
Negative array size
Syntax error
No error
Logic error
Q28
Q28 Which of these is not a principle of Object-Oriented Programming?
Inheritance
Polymorphism
Compilation
Abstraction
Q29
Q29 What is an instance variable in Java?
A variable defined inside a method
A variable defined outside of any method but inside a class
A static variable
A final variable
Q30
Q30 What is the purpose of a constructor in Java?
To create an instance of a class
To initialize variables
To define methods
To declare classes

