Diffrenece Between Constructor and Non-Static Block in Java

In Java there is a concept called Constructor Overloading. In such case more than one Constructor we create, and based on the argument we pass at the time of object creation, its respective constructor will  be called. But non-Static Block logic will be copied in every Constructor by compiler so, irrespective of Constructor execute, Non-Static Block Logic will execute. Observe Below Code.




So, the logic which must be execute irrespective of constructor execution must be placed in non-static block.

Comments

Popular posts from this blog

Components of C language

Decision making using if statement

Backslash character constants