A child class can use the constructor of its parent class.
The child class uses its constructor to update its unique fields.
And the child class uses the parent constructor to update inherited fields.
In this lesson, each child class is going to call the parent copy constructor.
So just a quick revision, super refers to the super class, which also means the parent class and super
rich brackets refers to the constructor of the super class, the constructor of the parent class.
If you want to call the the constructor of a parent class, you super an inside person, the object
you want to copy Fields' from.
So inside main, remove the array.
This was just to show you the flexibility of polymorphism.
And now set another object short to equal to a new copy of shirt.
But that's not going to work yet because we're calling it can't be constructive, it doesn't exist.
So here, copy the first instructor, as always.
And instead of getting values from a bunch of different parameters, we're going to get the values from
a source object.
And inside supercapacitor the source object.
Remember, super with brackets means we're calling a constructor.
So this means we're calling the copy constructor of the parent class parent class doesn't have a copy
constructor yet, so we're to have to create one.
So copy the first one, as always.
And instead of getting values from a bunch of different parameters, we're going to get the values from
a source, object, product source.
And once again, notice the polymorphism, the product copy constructor, expect a product object.
But we're passing in a shirt.
Remember that a class can take its own form or it can take the form of the class it's inheriting from,
in this case, the shirt object is taking the form of a product.
All right, put a break point, let's debugged there in time.
Creates a new object of the short class.
OK, this points to the current object that's being created.
Soares points to the object being passed in.
Here are passing the source object into the parent copy constructor.
There it copies the three fields from the source object into the current one.
And once the parent constructor is done, the child constructor copies the last field from the source
object into the current one, beautiful.
And now what if I want to create a copy of Pentz?
So Serpens to equal to a new copy of the pants object.
But that isn't going to work yet because we're calling a copy constructor that doesn't exist.
So here, copy the first constructor and instead of getting values from a bunch of different parameters,
it's going to get the values from a source object.
So inside, superbrain, a person, the source object.
And that's all.
Run the debugger.
It creates a new object of the pants class, the instructor receives a source object.
Here we're passing the source objecting to the parent copy constructor there, it copies three fields
from the source object into the current one.
And once the parent constructor is done, the child constructor copies of the last field from the source
object into the current one.
Let's recap a child class, can you do the copy constructor of its parent class?
The child uses the parent copy constructor to update inherited fields, and it can use its copy constructor
to update its unique fields.