A top class can use the constructor of its parent class.
The child class uses its constructor to update its fields.
The child class uses the parent constructor to update inherited fields.
In this lesson, each child, the class will call the parent constructor.
Super refers to the super class, which also means parent class.
Now, super with brackets refers to the constructor of the super class, the constructor of the parent
class.
If you want to call the constructor of a parent class, use super.
An inside in the parameters that the constructor expects.
Now, let's say our parent class, as of the following instructor, then this is how you would call
the parent constructor pretty cool.
Now, inside, man, we have two objects, put a break point and run the debugger.
Creates a new object of the short class.
OK.
The child constructor receives four parameters.
But it only updates one of them, the rest of them remain zero or no.
Now, it's impossible to update inherited fields from the child constructor, the child class needs
to use the parent constructor.
So inside product Java, critic, instructor, public product.
That receives three parameters, double price, string color, string, brand.
And update each field in the current object with a parameter, the stock price equals price, this color
equals color.
This brand equals brand.
OK, and now the child class needs to use the parent's constructor to update the fields that it inherits.
You can refer to the superclass, the parent class using super.
And you can refer to the super classes constructor by adding Brackett's.
And inside, you can add three of the parameters into the super constructor.
Now, the pants class also needs to use the parents constructor to update the fields that it inherits.
And that's it now we get to run the debugger.
It creates a new object of the short class.
The constructor receives four parameters.
It passes three of them into the parent constructor.
The parent constructor updates three fields in the current object that's being created, and once the
parent constructor is done, the child, the class uses its constructor to update its field.
OK, moving on to the object.
It creates a new object of the pants class, the constructor receives four parameters, three of them
are passed into the parent constructor.
The parent constructor updates three fields in the current object that's being created.
And once the parent constructor is done.
The child class is using its constructor to update its field.
All right, let's go back to the subject of polymorphism inheritance allows an object to take many forms.
In other words, inheritance allows an object to be polymorphic.
Our shirt to class inherits from the product class so we can declare this as type products, our pants
class also inherits from the product class so we can also declare it as type products.
Now, you might be wondering, why is polymorphism useful?
The answer to that is flexibility.
Here we create an object of the class, and here we created an object of the pants class, but they're
both of type product.
So we can store them inside the same array.
I can create an array of type product products is equal to a new array that can store product objects.
And here I can put the shirt.
And the pants.
Although this is a shirt object and this is a pants object, each one is taking the form of a product
object.
This is polymorphism.
A class can take its own form or it can take the form of the class it's inheriting from.
A child class can use the constructor of its parent class.
The child class uses its constructor to update its fields.
And the child class uses the parent constructor to update inherited fields.
Now, super with brackets refers to the constructor of the super class, the constructor of the parent
class.
If you want to call the constructor of a parent class, you super.
And inside Passan, the parameters that the constructor expects.