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

Can memory leak happen java?

1045


What is bubble sorting in java?

1108


What is java used for on a computer?

1034


Explain with example the concept of constant variable in java.

1257


Implement 2 stacks with just 1 array. The stack routines must not indicate overflow unless every slot in array is used.

1368


Is a class subclass of itself?

1124


Does treeset use compareto?

1021


Is integer a class?

1128


Can you use this() and super() both in a constructor?

1034


What is the epoch date?

1064


what is mutual exclusion? : Java thread

1065


What are the drawbacks of reflection?

1059


What are the disadvantages of object oriented programming?

1335


What is an i/o filter?

1956


What are 5 boolean operators?

1248