what is the difference between statis block and static
variable
Answers were Sorted based on User's Feedback
Answer / ramakrishna
Static block is the block which is executed first in the
program. Static variable is the common variable which is
shared by all the objects. Static variable is not specific
to any object.
| Is This Answer Correct ? | 11 Yes | 2 No |
Answer / 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 |
Answer / kiran
static variable are access and executed with objects or
methods(static or non-static) its a dependent.
static block executed and access independently when the
program starts
| Is This Answer Correct ? | 0 Yes | 0 No |
Answer / ravikiran
static block is used to initialize the variables during the
Jvm start up.
static variable is used to declare the class level
variables whose value remains ame for the whole class.
| Is This Answer Correct ? | 1 Yes | 4 No |
Answer / suresh.m
staticblock,static variables,static method are executed
before creating an object to be created to class.i think
there is no difference between them.
| Is This Answer Correct ? | 2 Yes | 11 No |
1.what is the exact difference between applet and frame? 2.Do we use main method in frames?
A abstract class extending an abstract class.Super class has both abstract and non-abstract methods.How can we implement abstract and non-abstract mehtods? Explain with snippet
What are the restrictions imposed on method overriding?
In which JDK version event-delegation model is introduced?
Which package is imported by default?
What is hash code collision?
Can you run java program without main method?
Is linked list a linear or non-linear data structure?
0 Answers Akamai Technologies,
What modifiers may be used with a top-level class?
Hai all I want to print given array in reverse order Ex: int a[]={1,2,3,4,5};display this array in reverse order.
What is type inference in java8?
What do you mean by order of precedence and associativity?