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 are static blocks and static initalizers in java ?
What is the function of static in java?
What's the access scope of protected access specifier?
What is singleton class in java and how can we make a class singleton?
Can a class have multiple subclasses?
What is the final blank variable?
What is javac_g?
What is ternary operator? Give an example.
What is immutable class in java?
What is increment in java?
Variables used in a switch statement can be used with which datatypes?
What is a top level class in java?
When can we say that threads are not lightweight process in java?
what are the disadvantages of indexes in oracle?
What is string english?