what is the difference between static block and static
method

Answers were Sorted based on User's Feedback



what is the difference between static block and static method..

Answer / aluru srinivasa rao

static block is executed first even before constructor is
invoked,static methods are invoked from a static method.

Is This Answer Correct ?    8 Yes 1 No

what is the difference between static block and static method..

Answer / anu

static block is execute first after the remaining blocks will executes.
static metods can executes using classname.staicmethodname

Is This Answer Correct ?    4 Yes 0 No

what is the difference between static block and static method..

Answer / chandu

write down compilation sequence order?
Static variable
Static block
Static method
?

Is This Answer Correct ?    5 Yes 3 No

what is the difference between static block and static method..

Answer / vilas paskanti

@Maruti
Main Method is a Special method That is called by the JVM.

Is This Answer Correct ?    2 Yes 0 No

what is the difference between static block and static method..

Answer / uday

static block is called when we create an object for that class,so it automatically excutes......
for static methods, we can call this methods by class names not by object....

Is This Answer Correct ?    2 Yes 1 No

what is the difference between static block and static method..

Answer / mittan aich

static block:
It is the class level one time execution block.After the compilation of the program when we go for running by using the command java <class name> then only the corresponding class will loaded in to RAM and 1st of all the static block of that class will execute even it run before the main method run.
->We place the class level initialization logic here like initialization of static variable.

Ex:

class Alpha
{
static
{
System.out.println("Alpha:static");
}
public void show()
{
System.out.println("Alpha:Show()");
}
}
public class Bita
{
static
{
System.out.println("Bita:static");
}
public static void main(String args[])
{
Alpha a=new Alpha();
a.show();
}
}


OUTPUT:
Bita:static

Alpha:static

Alpha:Show()
.......................
STATIC METHOD:
static method is a method which can loaded into the RAM without any object only class name is enough.
->Actually what happen fnds??A function will execute whn ever it only loaded into the RAm through a object.But some times our requirement is like this ,we have to execute a function but at that time no object cant be created for that
class.at that moment static method is very necessary
(consider about main method of java).
->static method and static variable does not allocated memory in object.but it allocate memory in CONTEXT area of that class.
EX:
class Gamma
{
int count1;
static int count2;
static void show()
{
System.out.println("Gamma:show()");
count1++;//error bcz non static variable.
count2++;//ok
}
public static void main(String args[])
{
Gamma.show();
}
}

Is This Answer Correct ?    1 Yes 0 No

what is the difference between static block and static method..

Answer / uday

maruthi we are calling main method....
without calling how it excutes........?

Is This Answer Correct ?    0 Yes 0 No

what is the difference between static block and static method..

Answer / sukhvider

static block executes whenever the class loaded in the Java virtual machine that means object is before going to main Method.

Is This Answer Correct ?    1 Yes 4 No

what is the difference between static block and static method..

Answer / hathwar

static block will execute when ever execution starts, it
means this block executes first of all, where as static
block have to call seperately and also it can call with out
object instance.

Is This Answer Correct ?    41 Yes 51 No

Post New Answer

More Core Java Interview Questions

Is empty in java?

0 Answers  


What is boolean logic?

0 Answers  


Are functions objects in java?

0 Answers  


What is a method in java?

0 Answers  


What is a conditional statement explain with example?

0 Answers  






How can we find size of the object ?

5 Answers   CTS, RazorSight,


Difference between method overloading and overriding.

0 Answers  


What is Interface?

8 Answers   BMC,


what is the difference between HashMap And HashTable?

5 Answers   Hexaware,


What are inner and anonymous class?

3 Answers  


What are the characteristics of java?

0 Answers  


What is stringwriter?

0 Answers  


Categories