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


Please Help Members By Posting Answers For Below Questions

What do you mean by exception handling in Java?

987


Print Vertical traversal of a Binary Tree.

802


What does file separator do in java?

748


Why we use set in java?

769


What is the purpose of javac exe?

785


How do you make an arraylist empty in java?

697


What is the purpose of a parameter?

787


How are observer and observable used in java programming?

759


Write a program to print count of empty strings in java 8?

756


What is data structure in java?

735


What is difference overloading and overriding?

809


What is console based application in java?

789


What is function and method in java?

725


What is the purpose of stub and skeleton?

756


How will you invoke any external process in java?

835