Java Interview Questions On Variables |
8. What is the difference between static and non-static variables?
Ans:
A static variable is associated with the class as a whole rather than with specific instances of a class. Non-static variables take on unique values with each object instance. |
9. What is casting?
Ans:
There are two types of casting, casting between primitive numeric types and casting between object references. Casting between numeric types is used to convert larger values, such as double values, to smaller values, such as byte values. Casting between object references is used to refer to an object by a compatible class, interface, or array type reference |
10. Explain About java member (instance) variables?
Ans:
- l Accessible from any method in the class.
- l Scope of the member variables is the entire class scope.
- l If there is no explicit initialization, then the value depends upon the data type of the member variable
|
11. What is the difference between a field variable and a local variable?
Ans:
A field variable is a variable that is declared as a member of a class. A local
variable is a variable that is declared local to a method. |
12. Explain About Technical behavior of the java automatic variables?
Ans:
- l Also known as local variables generally declared inside the methods.
- l Scope of the automatic variable is the scope of the method.
- l Automatic variables are not initialized by the compiler.
- l All the variables defined in a method scope must be initialized explicitly before being used.
|
13. What are all the Boolean literals?
Ans:
The boolean literals are true or false.
Example
boolean bool = false;
boolean b = true;
Note: A boolean can only be true or false, it cannot be assigned a number such as -1 or 0. |