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
What are some characteristics of interference class?
What is an accessor?
What does replaceall do in java?
Define jre i.e. Java runtime environment?
How do we access static members in java?
How many bits is size_t?
How do you implement tree mirroring in java?
What is float in java?
Why do we use return statement?
Is special character in java?
How do you test a method for an exception using junit?
What do you mean by thread safe?
What is singleton class and how can we make a class singleton?
What is the difference between class & structure?
Which one will take more memory: an int or integer?