javarevisited

javarevisited


What is Constructor in Java with Example – Constructor Chaining and Overloading

Posted: 12 Dec 2012 04:24 AM PST

What is constructor in Java
Constructor in Java is block of code which is executed at the time of Object creation. But other than getting called, Constructor is entirely different than methods and has some specific properties like name of constructor must be same as name of Class. Constructor also can not have any return type, constructor's are automatically chained by using this keyword and super. Since Constructor is used to create object, object initialization code is normally hosted in Constructor. Similar to method you can also overload constructor in Java. In this Java tutorial we will some important points about constructor in Java which is worth remembering for any Java programmer. It's also worth remember that any static initializer block is executed before constructor because they are executed when class is loaded into memory while constructors are executed when you create instance of any object e.g. using new() keyword.
Read more »


Post a Comment