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

33. try { 34. // some code here 35. } catch (NullPointerException e1) { 36. System.out.print(”a”); 37. } catch (RuntimeException e2) { 38. System.out.print(”b”); 39. } finally { 40. System.out.print(”c”); 41. } What is the result if a NullPointerException occurs on line 34? 1 c 2 a 3 ab 4 ac

5 Answers  


Which variables are stored in heap?

0 Answers  


what is the need to set path in java? how many ways to set path in java? Explain breif?

5 Answers  


We are seeing so many videos/audios as many web sited. But question is these videos or audios are stored in Databases ( Oracle, Mysql, Sybase,... ) or stored any file directory from there they will give the link for that? Pls explain and give sample code to achieve this one? Thanks, Seenu.

0 Answers   Symphony,


any other way to print the text without using System.out.println() in java?

5 Answers   IBM, Infosys,






Can subclass overriding method declare an exception if parent class method doesn't throw an exception?

0 Answers  


What is difference between checked and unchecked exception in java?

0 Answers  


How would you convert bytes to string?

0 Answers  


What are abstract methods in java?

0 Answers  


How many digits is int32?

0 Answers  


Why java is called not pure object oriented language?

0 Answers  


Explain Event handling in AWT?

1 Answers   Infosys, TCS,


Categories