what is the difference between static block and static
method

Answer Posted / kishore reddy

static{} blocks are executed on its own as soon as the
program starts. i.e before the main method is called where
as static() is called ONLY from another static method ie
main method.

static() has several restrictions:
1. Can ONLY call other static ()
2. MUST ONLY access static data
3. cant refer to super or this

Is This Answer Correct ?    14 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is static data type in java?

546


what is deadlock? : Java thread

529


State the merge-sort principle and its time complexity.

575


Can we change the scope of the overridden method in the subclass?

850


Difference between Linked list and Queue?

613






What is immutable class in java?

519


Is it possible to use Semaphore/ Mutex in an Interrupt Handler?

539


What are the restriction imposed on a static method or a static block of code?

600


What is a map? What are the implementations of map?

571


os is developed in c no java is more secured then c na why dont the os developed is developed using java

3527


What are local variables?

599


Write a java program to check if a number is prime or not?

539


What is the use of 'super' keyword inside a constructor?

562


What is the purpose of static methods and static variables?

545


What is the difference between path and classpath variables?

533