Two string is a method that returns every field as one string.
It's also a special method and you'll see why a very soon.
In this lesson, you're going to add it to string method to the car class.
To string, it connects every field of an object into a string.
Two string is a method that returns a string, and you can break it up into three parts.
It is public.
It has the name to string and it returns a string value.
In the car class, the phone, a two string method, public string.
To string.
The method returns a string.
And the string value needs to connect every field into a sentence.
So will return make.
And we'll connect the field, make.
And without a new line.
Then I'll say price.
And connect the price of the current object.
Then we'll connect the year field of the current object.
And we'll do the same for color.
In our last field as pirates, we're going to print the contents of this stop pirates using two string.
So when an object calls to string, it's going to connect every field from the object that calls it
into a string and return it.
Now, why is to string special when you print an object, Jávor looks for the two string method.
Try printing each object now and see what happens.
And check it out.
We printed every field in each object.
I hope your mind is blown because mine sure was when I found out about this.
But when you add a two string to your class, Java internally calls it, when you're printing the object
and the method returns a string that effectively describes the current object.
In practice, every class that models an object should have a two string method.
In this lesson, you add in a two string method to the car class.
When you had to string to your class, Jabor automatically calls it, when you're printing an object
of that class, ultimately to string makes it easy to print every field from the object that calls it
the current object.