Data Types & Variables
6.Which of the following is a valid variable declaration in Java?
-
A. int 1num = 10;
-
B. float my num = 5.5f;
-
C. double _value = 20.5;
-
D. char *letter = 'A';
double _value = 20.5;
double _value = 20.5;
7.What will be the output of the following Java program?
public class Main {
public static void main(String[] args) {
int x;
System.out.println(x);
}
}
-
A. 0
-
B. Compilation error
-
C. Garbage value
-
D. Runtime exception
Compilation error
Compilation error
8.What is the scope of a static variable in Java?
-
A. Limited to a single method
-
B. Limited to the class
-
C. Available to all classes in the same package
-
D. Available globally
Limited to the class
Limited to the class
9.What is the output of the following code?
public class Test {
static int x = 10;
public static void main(String[] args) {
System.out.println(x);
}
}
-
A. 10
-
B. Compilation error
-
C. 0
-
D. Runtime error
10
10
10.What will be the output of the following code?
public class Main {
public static void main(String[] args) {
final int x = 5;
x = 10;
System.out.println(x);
}
}
-
A. 10
-
B. 5
-
C. Compilation error
-
D. Runtime error
Compilation error
Compilation error