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
What is a function easy definition?
Is c better than java?
How will you call an Applet using Java Script Function?
When super keyword is used?
Why string is not thread safe?
Why can we not override static method?
What is the static method?
What do you mean by JVM?
Explain about strings in java?
How do you take thread dump in java?
Can we create a class inside a class in java?
What causes memory leak in java?
Describe method overriding
What is comparator in java?
why not override thread to make a runnable? : Java thread