1 00:00:00,450 --> 00:00:06,180 Hi this is it's hard once again welcome to the next video of this object oriented programming. 2 00:00:06,180 --> 00:00:09,570 Now this video is actually related to the previous video. 3 00:00:09,660 --> 00:00:15,630 So make sure you have followed my previous video then continue with this video so as to have a better 4 00:00:15,630 --> 00:00:17,340 understanding of the things. 5 00:00:17,400 --> 00:00:24,240 Now the companion objects are actually the same as the object but they are declared within a particular 6 00:00:24,240 --> 00:00:25,010 class. 7 00:00:25,020 --> 00:00:31,050 Now previously we defined the object outside a particular class as a high level member of the fight. 8 00:00:31,260 --> 00:00:35,040 So let us now check out how do we create the companion objects. 9 00:00:35,280 --> 00:00:40,700 So you inserted the intelligent Id previously we declared the customers data object. 10 00:00:40,890 --> 00:00:44,110 So here I would simply modify my code to some extent. 11 00:00:44,370 --> 00:00:50,730 And now we're only left with our object customers data that contains two fields of count and type of 12 00:00:50,730 --> 00:00:51,340 customers. 13 00:00:51,350 --> 00:00:55,370 And that third died previously we saw behaves like a static mattered. 14 00:00:55,490 --> 00:00:56,230 Right. 15 00:00:56,430 --> 00:01:01,810 Now suppose I want to declare this object customers data inside of class. 16 00:01:02,100 --> 00:01:09,520 So inside the class suppose I declare this object. 17 00:01:09,540 --> 00:01:13,260 So here I have to make this object as companion. 18 00:01:13,260 --> 00:01:17,980 Now Vennard declare this object as companion inside this Miklas. 19 00:01:18,060 --> 00:01:25,650 So all the fields of such ask around and type of customers actually behave like a static variable and 20 00:01:25,650 --> 00:01:26,990 static matters. 21 00:01:27,000 --> 00:01:33,220 Now previously I told you it behaves like the static variables and static methods but when the chord 22 00:01:33,230 --> 00:01:40,590 is compiled by the Cartland compiler this companion object is actually converted into the static fields 23 00:01:40,620 --> 00:01:42,640 and variables are amateurs. 24 00:01:42,660 --> 00:01:51,180 And I that is if you peep into the bytecode of this file you will find these are actually converted 25 00:01:51,300 --> 00:01:53,330 to static fields right now. 26 00:01:53,370 --> 00:01:59,830 Previously it was just behaving like the static variable and mattered but now it is actually like this 27 00:01:59,830 --> 00:02:02,320 tactic methods and variables. 28 00:02:02,340 --> 00:02:07,830 So how can we access this object customers data inside the main method. 29 00:02:07,830 --> 00:02:13,660 Now if you are using the companion object then you need not specify the customer's data name here. 30 00:02:13,680 --> 00:02:15,150 So you may remove it. 31 00:02:15,150 --> 00:02:15,900 Right. 32 00:02:16,080 --> 00:02:19,580 So inside this you can simply use Miklas dog. 33 00:02:19,620 --> 00:02:20,700 Let's stick around. 34 00:02:20,910 --> 00:02:23,050 And also Mike glass and DOD. 35 00:02:23,100 --> 00:02:24,100 Let's see. 36 00:02:24,270 --> 00:02:29,340 Type of customers like we did in the previous video with the help of object name. 37 00:02:29,340 --> 00:02:32,960 Now we're doing it with the help of my last name. 38 00:02:33,100 --> 00:02:35,440 So this was all about the companion object. 39 00:02:35,440 --> 00:02:39,450 Now suppose you want to call this method from inside some java file. 40 00:02:39,610 --> 00:02:45,930 So for that we need to make this function let's say with the help of the keyboard of JVM. 41 00:02:47,130 --> 00:02:49,260 Start the right. 42 00:02:49,510 --> 00:02:55,780 So now for the Javal function this method appears to be like the static method. 43 00:02:55,810 --> 00:02:56,340 Right. 44 00:02:56,410 --> 00:03:02,290 So using the Java Virtual Machine this method will be generated in the form of starting. 45 00:03:02,510 --> 00:03:08,650 So we will dive into this enervation of JVM starting in our upcoming videos then we'll talk about the 46 00:03:08,680 --> 00:03:10,660 advanced concept of Cartland. 47 00:03:10,690 --> 00:03:13,350 So as of now let us remove it. 48 00:03:13,390 --> 00:03:15,510 So this was all about this video. 49 00:03:15,580 --> 00:03:17,050 Thank you and have a good day.