In addition to overloading normal methods as explained in earlier post#76, you can also overload constructor methods.
Lets implement overloading constructors concept on Eclipse IDE
1. Launch Eclipse IDE, Create a new Java Project 'Project 003', Create a Class 'Box' and Declare the instance variables 'width', 'height' and 'depth' in Box class as shown below:
3. Create Box( ) constructor with all the three parameters as shown below:
So we have created three constructors with same name in the Class , but with different number of parameters. Java allows to create constructors with same number but which differ in number of parameters and type of parameters.
In this example, we have created three Box( ) constructors.
Click here to download the project containing 'Box' and 'ArgumentsPassing' classes used in this post (You can download the project and import into Eclipse IDE on your machine)
Please comment below to feedback or ask questions.
How to use Objects as parameters will be explained in next post.