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

Why declare Main() method as a static in java ?

0 Answers   HCL,


What is a consumer in java?

0 Answers  


Why singleton pattern is better than creating singleton class with static instance?

0 Answers  


How do you reverse a string in java without using string buffer?

0 Answers  


What is serialVersionUID and what is its need?

1 Answers   KPIT,


What is arrays aslist in java?

0 Answers  


How do you declare an array in java?

0 Answers  


Why is multiple inheritance not supported in java?

0 Answers  


What is the protocol is used in type4 driver?

4 Answers   CMC,


Does it matter in what order catch statements for filenotfoundexception and ioexception are written?

0 Answers  


What is the difference between throw and throws? What is the similarity between try and throw?

2 Answers  


What are the skills required for core java?

0 Answers  


Categories