what is the difference between statis block and static
variable
Answer Posted / manikandan [ gtec,vellore ]
static variables hold only one value and static block is a
set of code. static variables and static methods are loaded
before a main method.it loads one by one in top down approach.
consider this code:
class test
{
static{
System.out.println(i);//compile error bcas top down approach
}
static int i=1;
public static void main(String[]asd)
{
}
}
Is This Answer Correct ? | 6 Yes | 1 No |
Post New Answer View All Answers
What is jit and its use?
Define iterator and methods in iterator?
In a container there are 5 components. I want to display the all the components names, how will you do that one?
When throws keyword is used?
What is byte code and why is it important to java’s use for internet programming?
What are the different conditional statements?
What is loop in java?
When a thread is executing synchronized methods , then is it possible to execute other synchronized methods simultaneously by other threads?
Can we create a constructor in abstract class?
What restrictions are placed on method overriding in java programming?
How do you compare objects in java?
Break statement can be used as labels in java?
Is ++ operator thread-safe in java?
Can we create an object if a class doesn't have any constructor ( not even the default provided by constructor ) ?
How can I become a good programmer?