Stay with Java
Join this page to get in touch with all Java/J2EE technologies. For interview questions.
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.
Click here to claim your Sponsored Listing.
Category
Website
Address
Hyderabad
500072