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
Tell me are there implementations for sorting and searching in the java libarary?
What is get () in java?
Explain which of the following methods releases the lock when yield(), join(),sleep(),wait(),notify(), notifyall() methods are executed?
What does string [] args mean?
Why is inheritance used in java?
Define array. Tell me about 2-D array.
Does isempty check for null?
Is vector synchronized in java?
Explain the difference between jdk, jre, and jvm?
What is a memory leak in java?
What do you mean by local class?
What is void in java?
What do you understand by copy constructor in java?
Is singleton thread safe in java?
what is thread? What are the high-level thread states? : Java thread