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

Answer Posted / lolo

Static Block is executed when the Program starts.

Example :

public class StaticExample {

static{
System.out.println("Hello");
}

public static void main(String args[]){

}
}

When we run this program it will print Hello.

Static Methods are executed when those methods are called
from another static class or method

Example :

public class StaticExample {

static void printString(){
System.out.println("Hello");
}

static void testStaticMethod(){
printString();
}

public static void main(String args[]){
testStaticMethod();
}
}

Is This Answer Correct ?    134 Yes 4 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

How variables are stored in memory?

995


What are the skills required for core java?

1005


Explain about map interface in java?

986


I want my class to be developed in such a way that no other class (even derived class) can create its objects. How can I do so?

973


What will happen if non-synchronized method calls a static synchronized method and what kind of lock it acquires?

1087


What are the differences between heap and stack memory in java?

1045


What is a nonetype?

1119


What is pass by value?

937


Which list is sorted in java?

1022


How many bits is a float?

994


What is the difference between ArrayList and Vector? which one is better in Java

1120


What is the declaration statement?

932


Why is string builder not thread safe?

1053


How do you square a number in java?

1047


What is string made of?

947