1 00:00:00,470 --> 00:00:03,469 Two string is a method that returns every field as one string. 2 00:00:03,890 --> 00:00:07,040 It's also a special method and you'll see why a very soon. 3 00:00:07,880 --> 00:00:10,790 In this lesson, you're going to add it to string method to the car class. 4 00:00:13,480 --> 00:00:16,570 To string, it connects every field of an object into a string. 5 00:00:18,700 --> 00:00:22,600 Two string is a method that returns a string, and you can break it up into three parts. 6 00:00:23,110 --> 00:00:24,040 It is public. 7 00:00:24,160 --> 00:00:27,730 It has the name to string and it returns a string value. 8 00:00:30,960 --> 00:00:34,980 In the car class, the phone, a two string method, public string. 9 00:00:38,960 --> 00:00:39,680 To string. 10 00:00:45,150 --> 00:00:47,040 The method returns a string. 11 00:00:49,110 --> 00:00:52,110 And the string value needs to connect every field into a sentence. 12 00:00:53,880 --> 00:00:55,170 So will return make. 13 00:00:59,450 --> 00:01:01,010 And we'll connect the field, make. 14 00:01:07,140 --> 00:01:08,220 And without a new line. 15 00:01:14,250 --> 00:01:15,540 Then I'll say price. 16 00:01:22,890 --> 00:01:25,020 And connect the price of the current object. 17 00:01:32,240 --> 00:01:34,880 Then we'll connect the year field of the current object. 18 00:01:51,570 --> 00:01:53,160 And we'll do the same for color. 19 00:02:11,870 --> 00:02:16,610 In our last field as pirates, we're going to print the contents of this stop pirates using two string. 20 00:02:30,790 --> 00:02:36,040 So when an object calls to string, it's going to connect every field from the object that calls it 21 00:02:36,040 --> 00:02:37,630 into a string and return it. 22 00:02:40,090 --> 00:02:45,400 Now, why is to string special when you print an object, Jávor looks for the two string method. 23 00:02:47,180 --> 00:02:49,550 Try printing each object now and see what happens. 24 00:03:25,820 --> 00:03:26,570 And check it out. 25 00:03:26,600 --> 00:03:28,640 We printed every field in each object. 26 00:03:29,270 --> 00:03:33,110 I hope your mind is blown because mine sure was when I found out about this. 27 00:04:06,580 --> 00:04:11,920 But when you add a two string to your class, Java internally calls it, when you're printing the object 28 00:04:12,490 --> 00:04:16,390 and the method returns a string that effectively describes the current object. 29 00:04:22,270 --> 00:04:26,230 In practice, every class that models an object should have a two string method. 30 00:04:28,780 --> 00:04:31,570 In this lesson, you add in a two string method to the car class. 31 00:04:33,460 --> 00:04:37,900 When you had to string to your class, Jabor automatically calls it, when you're printing an object 32 00:04:37,900 --> 00:04:43,600 of that class, ultimately to string makes it easy to print every field from the object that calls it 33 00:04:43,780 --> 00:04:44,950 the current object.