Tuesday, January 8, 2019

Difference Between Constructor Overloading and Constructor Chaining?

Constructor Overloading
Constructor Chaining
1. Constructor overloading allows a class to have more than one constructor that have the same name as that of the class but differ only in terms of number or type of parameters. 1. Constructor chaining is a process of calling the one constructor from another constructor with respect to current object.
2. Constructor overloading is done to construct object in different ways. 2. Constructor chaining is done to call one constructor from another constructor.
3. Constructor overloading is achieved by declaring more than one constructor with same name but different parameters in a same class. 3. Constructor chaining is achieved by this() method.
4. Constructor overloading is flexible which allows us to create object in different way. 4. Constructor chaining is useful when we have many constructors in the class and want to reuse that constructor.

No comments:

Post a Comment