What is non static block in java

Answer Posted / syed

class demoStaticnonstatic
{
int i;
demoStaticnonstatic()//constructor
{
System.out.println("Under Constructor");
}//end
static//static block
{
System.out.println("Under static block");
}//end
//non-static block
{
System.out.println("Under non-static
block");
}//end
public static void main(String[] args)
{
System.out.println("under main method!");
demoStaticnonstatic d=new
demoStaticnonstatic();
}
}
STATIC BLOCK: is used in real time senarios, it provide
information regording the project(name.company,version etc)
before actually project executed.
NON-STATIC BLOCK:is used for - if we have many constructor
in a application and those constructor have same statements
instead of repeate those statement in each constructor,we
place that statement in non-static block.

Is This Answer Correct ?    25 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Tell me are there implementations for sorting and searching in the java libarary?

586


What is get () in java?

556


Explain which of the following methods releases the lock when yield(), join(),sleep(),wait(),notify(), notifyall() methods are executed?

601


What does string [] args mean?

533


Why is inheritance used in java?

595






Define array. Tell me about 2-D array.

580


Does isempty check for null?

541


Is vector synchronized in java?

543


Explain the difference between jdk, jre, and jvm?

582


What is a memory leak in java?

532


What do you mean by local class?

507


What is void in java?

579


What do you understand by copy constructor in java?

486


Is singleton thread safe in java?

538


what is thread? What are the high-level thread states? : Java thread

777