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

What are static blocks and static initalizers in java ?

750


What is the function of static in java?

734


What's the access scope of protected access specifier?

756


What is singleton class in java and how can we make a class singleton?

798


Can a class have multiple subclasses?

775






What is the final blank variable?

768


What is javac_g?

745


What is ternary operator? Give an example.

780


What is immutable class in java?

684


What is increment in java?

704


Variables used in a switch statement can be used with which datatypes?

698


What is a top level class in java?

713


When can we say that threads are not lightweight process in java?

796


what are the disadvantages of indexes in oracle?

2043


What is string english?

744