And now want to actually output the tutoring method that is related to these objects here.
OK.
So now I want to actually output these objects to the screen by calling them if it was trained on these
objects.
OK.
So here I can just type in the anemone that said text.
And inside the prentices I can just referred to the name of this object anemone.
OK.
That is strange.
So here I want to actually call the twisting method that is inside of this animal class as you can see
we have our twisting my foot here inside of this animal class and here I want to call this method to
this animate object.
And here again I want to type into the lion that sit text and inside the practices of the set text here
I need to refer to the name of this object lion that is three in my faith.
And as you can see here we have our twisting my head actually over right at the Smurfette in say this
like in class and you want to actually call the Smurfette Andi's like an object.
So now let's actually run our project and see what happens.
So now as you can see our application actually crashed.
OK.
Unfortunately I have 27 has stopped.
So let's actually go inside this log here.
OK.
And here as you can see it says that land does illegal argument exception the value of the power must
be greater than zero.
So this is the exception that you actually created here inside this Animal class.
I said that if the value of this power valuable is less than or equal to number 0 then for this legal
argument exception the value of the power must be greater than number 0.
So here this is how actually the exceptions work in your projects.
OK.
I need to actually change these values to other values so I can't just take in for example Number two
hundred for the power and number three hundred for the speed.
And here as you can see I need to change these numbers.
For example number 400 power and number 700 for this speed.
And now if I hit on my project let's see what happens.
So now as you can see our project actually our application is running on this emulator and here it says
animal named Bear animal color black animal power 200 and animal speed is 300.
And here it says animal named my lion animal color yellow animal power 400 animal species 700.
And here it says can are lying and fight through the fighting power of our lion is one hundred and seventy.
OK.
So hopefully death makes sense.
Let's actually use the power of putting morphism in Java.
OK here let's actually create an animal object.
Animal.
OK.
So I actually referred to the name of this Animal class.
And here I want to actually give a name to this animal object my animal OK assignment operator and now
I want to refer to the name of this lion object OK.
Lion.
So here as you can see I actually created an object from this animal class but here after the assignment
operator it refers to the name of this object.
OK.
So because there is actually an ease our relationship between these lion class and this animal class
because this lion class actually inherits all of the features and behaviors that is actually in say
that this animal class there is an is a relationship between these two classes.
OK.
So here I could actually refer to the name of this object the name of this line object and then assign
that object to this animal object.
Here to this animal is valuable.
OK.
Because that is and actually is a relationship between this animal class and this lion class ok at compile
time.
It is OK.
We can actually assign this value because that is an is a relationship between these two classes like
in an animal and we could actually we can actually assign these lion objects to this animal.
Valuable here.
OK.
Lion is actually an animal.
OK.
So I actually assigned this object to this animal variable.
And now let's actually output this object to this.
OK so here I can just take anti-X the polymorphism that said text.
And now inside the practices I can just type in my animal that string.
So because I actually fell to the name of this animal object here as you can see this animal ridable
you may think that it's going to actually whistling method that is inside of this animal class.
OK.
But it's going to actually call the two thing Meffert that is inside of this lion class.
OK.
As you can see we have a history of it in say that we live in class because at runtime it's going to
refer to this object located like an object that we actually assign to this animal and are variable
here.
OK.
So let's start on our project and see what happens.
So now as you can see our application is running on this emulator and here it says liar.
Using polymorphism monkey animal name my lion animal color yellow animal power 400 animal speed 700.
Can our lion fight through the fighting power over a lion.
One hundred and seventy all though we actually created an object from the Animal class.
OK here because we actually assign this like an object to this valuable at runtime it's going to actually
call the twisting method that is related to this like an object.
OK.
Because it's going to actually feel like an object.
OK.
That's the power of polymorphism then in Java.
And hopefully that makes sense.
And if you have any questions please post the discussion of the course and if you do not understand
the inheritance in Java Please watch their inheritance section of this course again.
So now let's actually go back and say this content underline the example and then here I need to actually
click on this clear cast here and now I need to actually drag a large takes you into this scroll you
here.
So here inside of this componentry section here inside this linearly sweaty call that's actually right
a large takes you into this linearly aesthetical that is inside of this vertical scroll view here.
OK and double click on it and delete the text of this text view and for the ID just type in here takes
the chats OK and then press Enter key on your keyboard.
So now let's actually go back and say this main activity the job right here and now let's actually create
an object from the sticks class so takes you the chat's assignment operator.
And then I need to test this object to a text view object find view by id r that Id dot TDX the checked
OK and then I need to put in a semi-colon at the end of my statement here.
OK so now let's actually create an object from this chat class.
So I just need to type in here Chad.
And the name of this object is my chats.
OK assignments operator new chats and here I need to specify some arguments for the constructor of this
chat class here.
As you can see chat object.
So for the name of this cat just type in here my chat.
OK comma the color of my child is for example black or white.
Ok come up and the power of my child is for example 400 comma and the speed of my cat is for example
seven hundred.
OK.
And then I need to put in a semicolon at the end of my statement here.
So now it's actually Outsports.
This cat is my cat.
Object to the screen so I just need to take it here to the chat.
That said text my child's dot two is three.
OK so now let's execute on our project and see what happens.
So now as you can see our application is running on DS emulator and if you scroll down here you can
see it says cats.
Animal named my chats.
OK.
So it is actually calling the 2st Meffert that is inside of this cat class yellow cake Chatz animal
name my cat animal color of white animal power 400 an animal speed seven hundred.
OK so now let's actually delete this line of code here first.
OK.
And then this actually creates an object from the Animal class.
OK.
And the name of my animal is for example my animal too.
OK.
Assignment operator my chats my chats and put a semi-colon at the end of your statement here.
OK so now listen to that Outsports this my animal to this clean.
OK.
So just they can hear the cat that said Tick's.
So say that the Prentice's of this set takes Smurfette just referred to the name of this animal to object
dot to a string.
So now let's actually again run our project and see what happens.
OK.
Now as you can see our application is running on this emulator here.
And here you can see again the string Meffert that is inside of this.
Inside this cat class is being called the cat's animal name my cats animal color white animal power
400 and animal speed is 700.
So as you can see here first of all they created an object from this cat's class called my Chatz.
OK in inline first T6 I actually created another object from this animal class and the name of this
object is my animal too.
OK.
And here I put an assignment operator and then I referred to the name of this my chat's object.
And I assigned this object to this value to this animal valuable here my animal too.
OK.
And 11:57 I actually called these two string Mefford on this my animal to object as you can see but
at runtime as you can see here.
It actually called this 2st Merfeld that is actually inside of these chats class.
OK.
Because that's right because at runtime it's going to actually refer to this object.
Keep my Chatz.
OK.
And then it's going to call this the string Meffert that is inside of these chats class.
It's actually called the twisting method that is actually related to this object.
And then we can see these values here.
OK.
So again that's the power of polymorphism and I hopefully that makes sense.
And if you have any questions about polymorphism then please post the discussion in the course and then
I'll do my best to answer all of your questions.
And thank you very much for watching and I'll see you in the next tutorial.