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

What is the indent key?

0 Answers  


Why null value is used in string?

0 Answers  


Write a program to find the whether a number is an Armstrong number or not?

0 Answers   Aspire, Infogain,


Implementations of set interface?

0 Answers  


What is defined as false sharing in the context of multithreading?

0 Answers  






what is mutual exclusion? : Java thread

0 Answers  


Why synchronization is important?

0 Answers  


Can we create more than one object singleton class?

0 Answers  


What is string and its types?

0 Answers  


Can we print null in java?

0 Answers  


Is there any tag in htm to upload and download files?

0 Answers  


Can you explain the usages of class.forname()?

0 Answers  


Categories