what is the difference between statis block and static
variable

Answers were Sorted based on User's Feedback



what is the difference between statis block and static variable..

Answer / ramakrishna

Static block is the block which is executed first in the
program. Static variable is the common variable which is
shared by all the objects. Static variable is not specific
to any object.

Is This Answer Correct ?    11 Yes 2 No

what is the difference between statis block and static variable..

Answer / manikandan [ gtec,vellore ]

static variables hold only one value and static block is a
set of code. static variables and static methods are loaded
before a main method.it loads one by one in top down approach.

consider this code:

class test
{
static{
System.out.println(i);//compile error bcas top down approach
}

static int i=1;
public static void main(String[]asd)
{

}
}

Is This Answer Correct ?    6 Yes 1 No

what is the difference between statis block and static variable..

Answer / kiran

static variable are access and executed with objects or
methods(static or non-static) its a dependent.
static block executed and access independently when the
program starts

Is This Answer Correct ?    0 Yes 0 No

what is the difference between statis block and static variable..

Answer / narasimha

i wolud like a new point to the above answer.
first the static varibles are inistalized then the static
bloks are executed.

Is This Answer Correct ?    3 Yes 5 No

what is the difference between statis block and static variable..

Answer / ravikiran

static block is used to initialize the variables during the
Jvm start up.
static variable is used to declare the class level
variables whose value remains ame for the whole class.

Is This Answer Correct ?    1 Yes 4 No

what is the difference between statis block and static variable..

Answer / ryry

ryryt

Is This Answer Correct ?    0 Yes 8 No

what is the difference between statis block and static variable..

Answer / suresh.m

staticblock,static variables,static method are executed
before creating an object to be created to class.i think
there is no difference between them.

Is This Answer Correct ?    2 Yes 11 No

Post New Answer

More Core Java Interview Questions

List interface?

2 Answers  


What happens if main method is not static?

0 Answers  


program to find 25 square = 625 here the 625 of last two digits is equal to 25, i don't know excatly what this type of number is called

1 Answers   Huawei,


Does sprintf add a null terminator?

0 Answers  


What is functional interface in javatpoint?

0 Answers  






what is the purpose of "virtual"?

0 Answers   EDS,


When does the compiler supply a default constructor for a class?

9 Answers   TCS,


Read data from console and print in one file. That would be in C:\temp ? Thanks, Bose

3 Answers   Oracle, Surya Software,


Why java is a platform independent? Explain

0 Answers  


What is an argument in java?

0 Answers  


What is 'finally' method in Exceptions?

4 Answers  


What will happen if there is a default method conflict as mentioned above and we have specified the same signature method in the base class instead of overriding in the existing class ?

0 Answers  


Categories