1 00:00:01,140 --> 00:00:02,190 Constructors. 2 00:00:02,580 --> 00:00:07,140 The constructors are special methods with special declarations. 3 00:00:08,240 --> 00:00:15,010 So construction declarations don't state a return type and their name matches the class name. 4 00:00:15,020 --> 00:00:22,340 So, for example, here, let's create an constructor of this class, my date and time to my date and 5 00:00:22,340 --> 00:00:22,640 time. 6 00:00:22,640 --> 00:00:26,420 And this is our constructor and assign it to year here. 7 00:00:27,120 --> 00:00:28,220 2019. 8 00:00:30,090 --> 00:00:31,710 Here and let's. 9 00:00:32,510 --> 00:00:40,520 The letter here, quote Here my date and my date and time clock here and print this clock here. 10 00:00:40,520 --> 00:00:48,050 So as you remember, we didn't we won't assign anything on clock and you will see what happens then. 11 00:00:49,010 --> 00:00:54,800 So let's print the hour clock here, as you can see here. 12 00:00:56,030 --> 00:00:56,660 So. 13 00:00:58,510 --> 00:01:00,460 Time is here. 14 00:01:00,820 --> 00:01:03,280 And the time. 15 00:01:03,430 --> 00:01:04,300 This is the year. 16 00:01:04,660 --> 00:01:06,190 The year is. 17 00:01:08,010 --> 00:01:14,340 Here and then we will pass clock dot get here method. 18 00:01:15,000 --> 00:01:15,870 So. 19 00:01:17,950 --> 00:01:18,460 Here. 20 00:01:21,310 --> 00:01:28,450 So the new constructor here, as you can see here, the new constructors. 21 00:01:28,600 --> 00:01:28,930 Yeah. 22 00:01:29,050 --> 00:01:38,440 Then the new constructor here takes a single year, takes a single year as a parameter. 23 00:01:38,440 --> 00:01:41,470 So actually let me write the parameter here. 24 00:01:41,470 --> 00:01:50,740 Integer year in and we will assign this year in or if set year. 25 00:01:51,520 --> 00:01:53,560 Is year in. 26 00:01:54,410 --> 00:01:58,130 Then here it comes to 2019. 27 00:01:59,700 --> 00:02:00,390 So. 28 00:02:01,970 --> 00:02:06,830 And as you can see, we need to match infrastructure initialization. 29 00:02:06,830 --> 00:02:15,330 So we need to add something, add a year variable because the constructors need a parameter here. 30 00:02:15,350 --> 00:02:16,370 So. 31 00:02:17,400 --> 00:02:18,600 For example, 2020. 32 00:02:19,640 --> 00:02:20,180 Here. 33 00:02:20,570 --> 00:02:24,440 And we can as you can see, we don't have any errors in the code. 34 00:02:24,440 --> 00:02:30,920 So here takes a single year in argument of type integer here. 35 00:02:30,920 --> 00:02:33,710 So you call the set year. 36 00:02:34,610 --> 00:02:38,630 Here's Seth here with year in. 37 00:02:38,870 --> 00:02:47,810 So if Seth here returns false the caller provided bad input and you override year end with a default 38 00:02:47,810 --> 00:02:50,450 value of 2019. 39 00:02:50,450 --> 00:02:59,480 So in main here you make a clock within the new constructor and then print the result. 40 00:03:00,200 --> 00:03:11,300 So the continuation of the my date and time clock year 2020 20 is called an initialization. 41 00:03:13,010 --> 00:03:13,380 Beer. 42 00:03:14,000 --> 00:03:16,970 So you might not like the idea that. 43 00:03:17,540 --> 00:03:25,150 Invalid year that in instances where slide silently corrected to 2019. 44 00:03:25,160 --> 00:03:26,480 I don't like it either. 45 00:03:26,480 --> 00:03:28,580 So exceptions solve this problem. 46 00:03:28,670 --> 00:03:33,500 So you will learn about them in next lectures about exceptions here.