0
What are the differences between default constructor, copy constructor and parameterized constructors?
5 Respostas
+ 3
MUHAMMADHU KALEEL AHAMED HANIM If you had to guess, what would you guess the differences are?
+ 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.
+ 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.
+ 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