0

What are the differences between default constructor, copy constructor and parameterized constructors?

29th Jun 2021, 5:22 AM
MUHAMMADHU KALEEL AHAMED HANIM
MUHAMMADHU KALEEL AHAMED HANIM - avatar
5 Réponses
+ 3
MUHAMMADHU KALEEL AHAMED HANIM If you had to guess, what would you guess the differences are?
29th Jun 2021, 5:32 AM
David Carroll
David Carroll - avatar
+ 3
MUHAMMADHU KALEEL AHAMED HANIM Thanks for the attempt to answer. It helps with knowing what to focus on with an answer. You're mostly right about default constructor in Java not having parameters. Technically... default constructors in Java applies to the compiler generated constructor that's automatically created when not defined in the source code. Otherwise, explicitly created constructors with no parameters would be referred to as parameterless constructors. NOTE: This reference is specific to Java and not all OOP languages. Parameterized constructors are certainly what you described. NOTE... In C#, a parameterized constructor can also define default values and therefore be called without passing arguments. C# refers to constructors that don't require passing any arguments to also be referred to as default constructors. Copy constructors are essentially a parameterized constructor that takes an instance of its class type and uses that instance to create a new copy of itself.
29th Jun 2021, 6:50 AM
David Carroll
David Carroll - avatar
29th Jun 2021, 5:46 AM
ChaoticDawg
ChaoticDawg - avatar
+ 2
The article from ChaoticDawg does a good job of explaining copy constructors. Ultimately... you can see there are some overlap in the meanings of these terms. For example, all copy constructors are parameterized constructors, but not all parameterized constructors are copy constructors. The overlap is further expanded when applying these terms to other OOP languages. Hope this was helpful.
29th Jun 2021, 6:55 AM
David Carroll
David Carroll - avatar
+ 1
If you had to guess, what would you guess the differences are? Default constructor don't have parameters, and parameter constructor have parameter. But I have no idea about copy constructor
29th Jun 2021, 5:37 AM
MUHAMMADHU KALEEL AHAMED HANIM
MUHAMMADHU KALEEL AHAMED HANIM - avatar