Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

What is design pattern and there types?

2 Answers   Cap Gemini,


How to reverse a string in java?

0 Answers  


Explain java code for recursive solution's base case?

0 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  


What is supplier in java?

0 Answers  


Differentiate Vector and ArrayList?

6 Answers   Max Telecom, Wipro,


What are the latest versions in JAVA related areas?

3 Answers   Netcraft,


what is encapsulation in java? Explain

0 Answers  


Can private class be inherited in java?

0 Answers  


How will you measure that int takes up only 32 bits in memory?

2 Answers   Rolta,


"we cannot create an object of interface but we can create a variable of it".diacuss the statement with the help of an example.

2 Answers  


What is array initialization in java?

0 Answers  


Categories