What is non static block in java
Answer Posted / sujay
An instance block in a java program can be said to be a
non-static block. The scope of a static block is same as the
scope of that class, It will be loaded into the memory when
the class is loaded into the memory and unloaded at the time
of class unloading. But the scope of an instance
block(non-static block) is same as the scope of the object
of that class, it will be loaded into the memory when every
an objected is created and destroyed when that object is
destroyed. So, static block is created only once at the time
of class loading and globally available to all the objects
of that class where as a separate copy of instance block is
created for each object.
class MyClass
{
static
{
System.out.println("I am static, available for all
the objects of this class!");
}
{
System.out.println("I am non-static, available as a
separate copy for each object that is created from this
class!");
}
}
| Is This Answer Correct ? | 2 Yes | 0 No |
Post New Answer View All Answers
What is overriding in java?
When should we create our own custom exception classes?
What is the byte range?
What is OOP Language?
Tell some latest versions in JAVA related areas?
Difference between object and reference?
Why is java architectural neutral?
What is a dynamic array in java?
What are keyboard events?
What is the use of toarray () in java?
Is it possible to write a regular expression to check if string is a number?
What is application tier?
What is the difference between import java.util.date and java .util?
What is the final access modifier in java?
Are registers volatile?