1 00:00:00,900 --> 00:00:03,510 The constructor runs as soon as you create your object. 2 00:00:05,040 --> 00:00:10,380 We created a new object of the dealership class, the field is an array of car objects, as always, 3 00:00:10,380 --> 00:00:15,690 every field starts off as zero or null, and it's the constructors job to update every field as soon 4 00:00:15,690 --> 00:00:17,100 as we create the object. 5 00:00:21,420 --> 00:00:24,810 So in this lesson, you're going to add a constructor to your dealership class. 6 00:00:27,280 --> 00:00:31,650 So we can, at a dealership, instruct you in your dealership class, as always, it's going to be public, 7 00:00:32,290 --> 00:00:34,360 it's going to share the same name as the class. 8 00:00:36,790 --> 00:00:38,740 And for now, I'm not going to add parameters. 9 00:00:39,360 --> 00:00:43,720 I know what you're thinking, we should be passing in a parameter, but I don't want to do that until 10 00:00:43,720 --> 00:00:46,260 you're more comfortable working with an array of objects. 11 00:00:46,630 --> 00:00:49,930 So for the time being, the constructor is going to remain incomplete. 12 00:00:52,870 --> 00:00:57,640 All I want for now is for the cars failed to start off with a room for three elements and they're all 13 00:00:57,640 --> 00:00:58,370 going to be empty. 14 00:00:59,350 --> 00:01:01,810 Think of each element in the area as a parking space. 15 00:01:04,489 --> 00:01:07,970 One by one, we're going to add car objects to each parking space. 16 00:01:18,070 --> 00:01:20,170 So in the constructor, we can set the field. 17 00:01:24,190 --> 00:01:27,400 Equal to a new car array with the size of three. 18 00:01:28,420 --> 00:01:33,250 The requirements don't mention how many cars the dealership can hold until you're free to make the array 19 00:01:33,250 --> 00:01:34,150 as big as you want. 20 00:01:34,540 --> 00:01:35,590 For now, I'm choosing three. 21 00:01:37,910 --> 00:01:43,670 And since the field is private and we don't have any getters, print the contents inside the constructor 22 00:01:44,300 --> 00:01:45,770 print line erase. 23 00:01:54,200 --> 00:01:54,920 To string. 24 00:01:58,420 --> 00:01:59,560 This Dakar's. 25 00:02:02,090 --> 00:02:02,870 And that's all. 26 00:02:23,210 --> 00:02:26,750 When you're on the code, the first line creates an object of the dealership class. 27 00:02:29,150 --> 00:02:34,880 Your brackets have no arguments, so Java runs the constructor with no parameters, the constructor 28 00:02:34,880 --> 00:02:41,060 set your field equal to enumerate with the size of three and the array cars has three open spots that 29 00:02:41,060 --> 00:02:42,140 we can put Khazen. 30 00:02:48,990 --> 00:02:50,610 So remove the print statement. 31 00:02:51,630 --> 00:02:54,360 You should only ever have field updates in a constructor. 32 00:02:56,020 --> 00:02:56,650 And that's all. 33 00:03:00,080 --> 00:03:01,910 In this lesson, you added a constructor. 34 00:03:04,380 --> 00:03:06,330 First, you credit a dealership object. 35 00:03:08,260 --> 00:03:12,400 Your brackets have no arguments, so Java runs the constructor with no parameters. 36 00:03:15,320 --> 00:03:20,600 The constructor set your field equal to a new era with a size of three, and now the array has three 37 00:03:20,600 --> 00:03:26,630 open spots that we can add cars to, but we don't have a way of accessing or updating the fields from 38 00:03:26,630 --> 00:03:27,180 outside. 39 00:03:27,530 --> 00:03:30,170 So the next step is data getter and a setter.