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

Can we declare a constructor as final?

903


Why 1 is not a prime number?

781


What is api data?

757


What is the use of keywords in java?

762


What is the difference between member variables initialization and assignment in a constructor?

897


How will you invoke any external process in java?

824


What is difference between next () and nextline () in java?

754


What are the differences between stringbuffer and stringbuilder?

732


what is meant by encapsulation?

831


What java is used for?

824


What are the important features of Java 11 release?

779


How big is a boolean?

794


What does t in java mean?

739


Why is string buffer better than string ?

793


What is vector?

773