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
Can memory leak happen java?
What is bubble sorting in java?
What is java used for on a computer?
Explain with example the concept of constant variable in java.
Implement 2 stacks with just 1 array. The stack routines must not indicate overflow unless every slot in array is used.
Is a class subclass of itself?
Does treeset use compareto?
Is integer a class?
Can you use this() and super() both in a constructor?
What is the epoch date?
what is mutual exclusion? : Java thread
What are the drawbacks of reflection?
What are the disadvantages of object oriented programming?
What is an i/o filter?
What are 5 boolean operators?