Question 1
What is the maximum value that can be stored in a byte variable in Java?
1
64
2
255
3
32767
4
127
Question 2
Which data type is used to store a single character in Java?
1
char
2
ch
3
string
4
int
Question 3
What is the default value of an int variable in Java if it's not explicitly initialized?
1
1
2
0
3
null
4
garbage value
Question 4
What will be the output of following Java Code?
public class Main {
public static void main(String[] args) {
int[] arr = new int[3];
for (int i = 0; i < arr.length; i++) {
System.out.print(arr[i]);
}
}
}1
000
2
error
3
garbage value
4
111
5
0 0 0
Question 5
Which of the following is not a valid identifier for a Java variable?
1
_myvar
2
$var
3
3rdvar
4
my_var
Question 6
What is the size of a long variable in Java?
1
4 bytes
2
8 bytes
3
2 bytes
4
12 bytes
Question 7
What is the range of values that can be stored in a short variable in Java?
1
0 to 65,535
2
-32,768 to 32,767
3
0 to 255
4
-128 to 127
Question 8
Which of the following is a primitive data type in Java?
1
String
2
char
3
Integer
4
Boolean
Question 9
Which keyword is used to declare a variable that can hold a reference to an object of any class in Java?
1
object
2
class
3
var
4
genric
Question 10
What is the default value of a boolean variable in Java if it is not explicitly initialized?
1
0
2
false
3
true
4
null
Question 11
Which of the following is the correct way to declare a hexadecimal value in Java?
1
#1A
2
0b1A
3
0x1A
4
#1A
Question 12
What is the minimum value that can be stored in a char variable in Java?
1
0
2
-128
3
-32768
4
'a'
Question 13
Which of the following is not a primitive data type in Java?
1
int
2
byte
3
char
4
String
Question 14
What is the default value of a double variable in Java if it's not explicitly initialized?
1
null
2
1.0
3
garbage value
4
0.0
Question 15
What will be the output of following Java Code?
public class Main {
public static void main(String[] args) {
int myVar;
System.out.print(myVar);
}
}1
runtime error
2
0
3
compile time error
4
garbage value
Question 16
What will be the output of following Java Code?
public class Main {
static int myVar;
public static void main(String[] args) {
System.out.print(myVar);
}
}1
0
2
compile time error
3
runtime error
4
garbage value
Question 17
What will be the output of following Java Code?
public class Main {
public static void main(String[] args) {
static int myVar;
System.out.print(myVar);
}
}1
0
2
compile time error
3
garbage value
4
runtime error
Question 18
What will be the output of following Java Code?
public class Main {
int myVar;
public static void main(String[] args) {
Main obj = new Main();
System.out.print(obj.myVar);
}
}1
garbage value
2
compile time error
3
runtime error
4
0
Question 19
What is the keyword used to declare a constant value in Java?
1
static
2
final
3
const
4
constant
Question 20
Which of the following is not a valid way to declare an integer variable in Java?
1
int x =42;
2
int x = 0x42;
3
int x = -42;
4
int x = 42.5;
Question 21
What is the default value of a char variable in Java if it's not explicitly initialized?
1
'0'
2
'\u0000'
3
null
4
''
Question 22
What will be the output of following Java Code?
public class Main {
public static void main(String[] args) {
char myVar;
System.out.print(myVar);
}
}1
runtime error
2
garbage value
3
compile time error
4
0
Question 23
What will be the output of following Java Code?
public class Main {
static char myVar;
public static void main(String[] args) {
System.out.print(myVar);
}
}1
An empty space (because the default value of myVar is '\u0000')
2
null
3
0
4
compile time error
Question 24
What will be the output of following Java Code?
public class Main {
public static void main(String[] args) {
static char myVar;
System.out.print(myVar);
}
}1
garbage value
2
0
3
runtime error
4
compile time error
Question 25
What will be the output of following Java Code?
public class Main {
char myVar;
public static void main(String[] args) {
Main obj = new Main();
System.out.print(obj.myVar);
}
}1
null
2
compile time error
3
0
4
''
5
An empty space (because the default value of myVar is '\u0000')
Question 26
Which of the following is the correct way to declare a boolean variable named isJava and initialize it to true in Java?
1
bool = true;
2
bool isJava = true;
3
boolean isJava = true;
4
boolean = true;
Question 27
What is the size of a float variable in Java?
1
4 bytes
2
12 bytes
3
8 bytes
4
2 bytes
Question 28
What is the size of a double variable in Java?
1
4 bytes
2
8 bytes
3
2 bytes
4
12 bytes
Question 29
What is the range of values that can be stored in a char variable in Java?
1
0 to 255
2
0 to 65535
3
-128 to 127
4
-32768 to 32767
Question 30
What is the default value of a boolean array element in Java if it's not explicitly initialized?
1
true
2
false
3
0
4
null
