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 features of interfaces in java?
Can we assign the reference to this variable?
What is the purpose of static methods and static variables?
What is indexof in java?
Write the algorithm to check the number non-leaf nodes in a tree.
How does compareto method work?
Which object oriented concept is achieved by using overloading and overriding?
Is string is a data type in java?
I have multiple constructors defined in a class. Is it possible to call a constructor from another constructor’s body?
What are parsing rules?
What is pojo class in java?
What’s the difference between callable and runnable?
What is the benefit of singleton pattern?
What are the procedures?
What is anti pattern in programming?