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

Accenture NJ mostly ask question on Collection like 1)How to sort Objcts and how treeset sort them 2)Explain mechanism of Hashcode finding in Java 3)Name some of the Sorted collection.

2 Answers   Accenture,


Can we catch more than one exception in a single catch block?

0 Answers  


How many types of methods are there?

0 Answers  


What is floor in java?

0 Answers  


What is meant by main method?

0 Answers  


Explain what is encapsulation?

0 Answers  


How do you check if a number is a perfect square?

0 Answers  


How can we handle runtime exceptions? write one sample program? Can we write runtime exceptions beside the throws key word? if yes write sample program?

1 Answers   Huawei,


What is the access scope of protected access specifier?

0 Answers  


In C we use only compiler. Why java uses both compiler and interpreter? What is its significance?

5 Answers  


Is string a wrapper class?

0 Answers  


what is the purpose of class "Object" which is base class for all classes?

3 Answers  


Categories