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

what is static import in java? Explain

967


How garbage collection is done in java?

998


Can we declare an interface as final?

999


Can static method access instance variables ?

1077


Explain about main() method in java ?

1014


Discuss 2D arrays.

1007


What does the three dot emoji mean?

1058


what is the significance of listiterator in java?

1039


How will you get the platform dependent values like line separator, path separator, etc., ?

961


What is OOP Language?

1025


Explain with example the concept of constant variable in java.

1112


What is a parameter in matrices?

995


Explain about instanceof operator in java?

1001


What is the purpose of lambda expressions?

1007


What are inbuilt functions?

943