Core Java Interview Questions About Static Members

This Core java interview questions about static members page provide information about all the java interview question on class members including static block, static method, static variable, static user method, need to static block, variable, method and much more.


What is static block?
Block of instructions having no identity.


Can we access static block explicitly?
No, JVM invokes implicitly at the time of class loading.


Among Static block and main method, which one executes first?
static block executes before the main method.


Why static block?
The static block provides loading information.


Is it mandatory to define the static block in every class?
static block is optional block.


Can we define more than one static block in a single class?
Yes allowed and all these blocks execute in the defined order.


Why static block execution before the main method?
The main method is the start point of communication with Object.
To communicate, basic information is required.
Hence static block executes before the main method.


How to access static members in java application?
Either by using the class name or by using object reference variable.


What is static variable?
Declaration of a variable inside a class and outside of all the blocks and methods.


What are the default values of int and boolean?
0 and false.


What is the static method?
Represents common functionality(free access) of an object.
A method which we can access directly by using the class name.


What is Local variable?
Declaration of a variable inside any block or method.


How to access local variables in java?
Local variables can be accessed directly.


Can we access local variable everywhere in the application?
We can access the variable only inside the block in which it has declared.


What is the default value of integer local variable?
Local variables must be initialized before its use.


How to access static & local variables in Java?
Local variables can be accessed directly.
static variables can be accessed using class name or object reference variable.


>Core Java Data Types Interview Questions<

Share this