Hi this is it's hard once again welcome to the next video of this object oriented programming.
Now this video is actually related to the previous video.
So make sure you have followed my previous video then continue with this video so as to have a better
understanding of the things.
Now the companion objects are actually the same as the object but they are declared within a particular
class.
Now previously we defined the object outside a particular class as a high level member of the fight.
So let us now check out how do we create the companion objects.
So you inserted the intelligent Id previously we declared the customers data object.
So here I would simply modify my code to some extent.
And now we're only left with our object customers data that contains two fields of count and type of
customers.
And that third died previously we saw behaves like a static mattered.
Right.
Now suppose I want to declare this object customers data inside of class.
So inside the class suppose I declare this object.
So here I have to make this object as companion.
Now Vennard declare this object as companion inside this Miklas.
So all the fields of such ask around and type of customers actually behave like a static variable and
static matters.
Now previously I told you it behaves like the static variables and static methods but when the chord
is compiled by the Cartland compiler this companion object is actually converted into the static fields
and variables are amateurs.
And I that is if you peep into the bytecode of this file you will find these are actually converted
to static fields right now.
Previously it was just behaving like the static variable and mattered but now it is actually like this
tactic methods and variables.
So how can we access this object customers data inside the main method.
Now if you are using the companion object then you need not specify the customer's data name here.
So you may remove it.
Right.
So inside this you can simply use Miklas dog.
Let's stick around.
And also Mike glass and DOD.
Let's see.
Type of customers like we did in the previous video with the help of object name.
Now we're doing it with the help of my last name.
So this was all about the companion object.
Now suppose you want to call this method from inside some java file.
So for that we need to make this function let's say with the help of the keyboard of JVM.
Start the right.
So now for the Javal function this method appears to be like the static method.
Right.
So using the Java Virtual Machine this method will be generated in the form of starting.
So we will dive into this enervation of JVM starting in our upcoming videos then we'll talk about the
advanced concept of Cartland.
So as of now let us remove it.
So this was all about this video.
Thank you and have a good day.