- B1
- CTrue
- DFalse
Time Taken:
Correct Answer:
Wrong Answer:
Percentage: %
False is the correct default value of a Boolean type.
The default value of a boolean variable in Java:
In Java, if you declare a boolean instance variable (not local variable) and do not initialize it, its default value is false. ✅
False and True (capitalized) are not valid in Java.
0 is an integer, not boolean.
Answer: false
'\n' in Java?'\n' is a character literal → newline character.
In Java, every character is stored in char type.
char in JavaUnlike C/C++, where char is 1 byte,
In Java, char is always 2 bytes (16 bits) because Java uses Unicode.
'\n' is simply a char, so its size = 2 bytes.
✅ Answer: (a) 2 bytes
7.0 + (-3.0) = 4.0
✅ Answer: (d) 4.0
For a String, length() returns an int (number of characters).
✅ Not a String.
Returns the character (char) at a given index.
✅ Not a String.
Returns a new String with characters replaced.
✅ This one returns a String.
Returns the int index of the substring (or -1 if not found).
✅ Not a String.
Checks for equality between the input expression and case labels → ✅ True
Supports floating point constants → ❌ Not allowed
In Java, switch can only work with:
byte, short, char, int
Their wrapper classes (Byte, Short, Character, Integer)
String
enum types
float and double are not allowed.
break is used to exit the switch block → ✅ True
Case labels are unique → ✅ True
✅ Answer: (b) supports floating point constants
char ch[] = { 'A', 'E', 'T', '0', 'U' };
System.out.println(ch[0] * 2);
ch[0]ch[0] → 'A'
In Java, char is a numeric type under the hood (Unicode value)
Unicode of 'A' → 65
ch[0] * 2 = 65 * 2 = 130
Since we are using arithmetic, the result is int, not char.
So it prints 130
✅ Answer: (b) 130
public class LoopTest { public static void main(String[] args) { int count = 0; // to count iterations for (int i = 11; i <= 30; i += 2) { System.out.println("i = " + i); count++; } System.out.println("Total iterations: " + count); } }
for (int i = 11; i <= 30; i += 2)
Sequence: 11, 13, 15, …, 29
Total iterations: (30-11)/2 + 1 = 10 ✅
Looks correct.
for (int i = 11; i <= 30; i += 3)
Sequence: 11, 14, 17, …
Iterations: (30-11)/3 + 1 = 7 ❌
Not correct.
for (int i = 11; i < 20; i++)
Sequence: 11, 12, …, 19
Iterations: 20-11 = 9 ❌
Not correct.
for (int i = 11; i <= 21; i++)
Sequence: 11, 12, …, 21
Iterations: 21-11+1 = 11 ❌
Not correct.
✅ Answer: (a) for (int i=11;i<=30;i+=2)
Let's carefully analyze:
We have a string array String s[]. We want the number of elements in the array.
(a) s.length → ✅ Correct. For arrays in Java, .length without parentheses gives the number of elements.
(b) s.length() → ❌ Incorrect. length() is used for String objects, not arrays.
(c) length(s) → ❌ Not valid in Java.
(d) len(s) → ❌ Python syntax, not Java.
Answer: (a) s.length