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
How are observer and observable used in java programming?
What is the difference between equals() and == in java?
What is the dot operator?
How can we pass argument to a function by reference instead of pass by value?
What is int short for?
Define Multiprogramming and Multiprocessing in java.
Why java is not 100% object-oriented?
What is jit compiler ?
How do I know if java is installed?
Why we used vector class?
What is ctrl m character?
What is t in generics in java?
Why collection doesn’t extend cloneable and serializable interfaces?
Is arraylist ordered in java?
Can we override constructors in java?