Stay with Java

Stay with Java

Share

Join this page to get in touch with all Java/J2EE technologies. For interview questions.

03/07/2015

Constructor vs Instance block

Both instance block and constructor will be executed automatically for every object creation but instance block is first followed by constructor.

1. The main objective of constructor is to perform initialization of an object.

2. Other than initialization if we want to perform any activity for every object creation we have to define that activity inside instance block.

3. Both concepts having different purposes hence replacing one concept with another concept is not possible.

4. Constructor can take arguments but instance block can’t take any arguments hence we can’t replace constructor concept with instance block. Similarly we can’t replace instance block purpose with constructor.

Want your business to be the top-listed Computer & Electronics Service in Hyderabad?
Click here to claim your Sponsored Listing.

Website

Address


Hyderabad
500072