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
Explain the private field modifier?
Can we access instance variables within static methods ?
What is jit compiler in java?
How can you add and remove nodes in jtree?
Why is a constant variable important?
Should database connections be singleton?
Tell us something about set interface.
Define array. Tell me about 2-D array.
What is constructor in java ?
What is array size in java?
What are the two types of java programming?
What is jit compiler ?
Can we override constructor in java?
what is an objects lock and which objects have locks? : Java thread
How many bits is a boolean?