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 java argument list?
What are synchronized methods and synchronized statements in java programming?
What is final?
How much is a java license?
Why webdriver is an interface?
What is the difference between super class & sub class?
Why string is immutable or final in java
Why can't we use static class instead of singleton?
How would you dynamically allocate memory to an array?
What are the 4 types of research methods?
How do you end a program?
What is a default constraint?
Can a class have 2 constructors?
What is a method declaration?
What technique is carried out to find out if a particular string is empty?