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
How many types of constructors are used in java?
When will we use them?
What is better- service oriented or batch oriented solutions?
What is a get method?
Why hashset is used in java?
What is the use of singleton class?
What is set string?
Can a string be null?
Is empty .java file name a valid source file name?
What are the basics of core java?
What is a protected void?
What are the problems faced by java programmers who don't use layout managers?
Tell us something about set interface.
Can we make the abstract methods static in java?
Can we override data members in java?