Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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


Please Help Members By Posting Answers For Below Questions

Is there any limitation of using inheritance?

1087


Using callable statement how can you pass out parameters, explain with example?

1229


What is the method to declare member of a class static?

1009


How we can skip finally block of exception even if some exception occurs in the exception block in java?

948


Can we create an object if a class doesn't have any constructor ( not even the default provided by constructor ) ?

1082


What is difference in between java class and bean?

1090


What’s the difference between unit, integration and functional testing?

1106


What is floating data type?

981


Why hashset is used in java?

1067


What is the difference between sop and work instruction?

927


What is the use of volatile in java?

1059


What happens if we don’t define serial version uid?

1028


Differences between C and Java?

1197


Can we compare two strings in java?

1022


Is array passed by reference in java?

1025