Java Programming Multiple Choice Questions - Variable
This section focuses on the "Variables" in Java programming. These Multiple Choice Questions (MCQ) should be practiced to improve the Java programming skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements and other competitive examinations.
1. A ________ provides us with named storage that our programs can manipulate.
A. data type
B. constants
C. operators
D. variable
View Answer
Ans : D
Explanation: A variable provides us with named storage that our programs can manipulate.
2. Each variable in Java has a specific type, which determines the size and layout of the variable's memory.
A. TRUE
B. FALSE
C. Can be true or false
D. Can not say
View Answer
Ans : A
Explanation: True, Each variable in Java has a specific type, which determines the size and layout of the variable's memory.
3. To declare more than one variable of the specified type, we can use a __________ list.
A. colon-separated
B. bracket-separated
C. comma-separated
D. None of the above
View Answer
Ans : C
Explanation: To declare more than one variable of the specified type, you can use a comma-separated list.
4. How many kinds of variables in Java?
A. 2
B. 3
C. 4
D. 5
View Answer
Ans : B
Explanation: There are three kinds of variables in Java : Local variables, Instance variables and Class/Static variables
5. Local variables are declared in?
A. methods
B. constructors
C. blocks
D. All of the above
View Answer
Ans : D
Explanation: Local variables are declared in methods, constructors, or blocks.
6. What is true about Instance Variables in java?
A. Instance variables are declared in a class
B. When a space is allocated for an object in the heap, a slot for each instance variable value is created.
C. Instance variables can be declared in class level before or after use
D. All of the above
View Answer
Ans : D
Explanation: All of the above are true about Instance Variables in java
7. Which variables have no default values?
A. Static Variables
B. Instance Variables
C. Local Variable
D. Both A and B
View Answer
Ans : C
Explanation: There is no default value for local variables, so local variables should be declared and an initial value should be assigned before the first use.
8. Static variables can be accessed by calling with the?
A. Object name
B. Class name
C. Function name
D. Can not say
View Answer
Ans : B
Explanation: Static variables can be accessed by calling with the class name ClassName.VariableName.
9. Which of the following is an Example of variable initialization?
A. int a, b, c;
B. int a = 10, b = 10;
C. int 10 = a;
D. None of the above
View Answer
Ans : B
Explanation: int a = 10, b = 10; is an Example of initialization
10. Access modifiers cannot be used for local variables.
A. Yes
B. No
C. Can be yes or no
D. Can not say
View Answer
Ans : A
Explanation: Yes, Access modifiers cannot be used for local variables.
Discussion