Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
Multiple methods in the same class can have the same name. They're called overloaded methods.
-
0:00
In C#, a class can have multiple methods with the same name.
-
0:03
For example, there are 18 methods in the console class all named write.
-
0:08
They all take different types and numbers of arguments.
-
0:11
This is useful because not all data that a method can handle comes in the same type.
-
0:18
The DistanceTo method right now calculates the distance between a point and
-
0:22
the x and y values parsed in.
-
0:24
We could also have a DistanceTo method that
-
0:28
calculates the distance between two-point objects.
-
0:34
This method can just call the other DistanceTo method like this.
-
0:48
What we've just done is overloaded the DistanceTo method.
-
0:51
To overload a method means to have two methods with the same name that take
-
0:56
different parameters.
-
0:57
As you can see, methods are the moving parts of an object.
-
1:01
It's where the code that does stuff lives.
-
1:04
Fields in a class are the substance of the object.
-
1:08
They're what make two objects of the same type unique.
-
1:12
They contain the object's data.
-
1:15
You may have also noticed that methods all use the fields in some way.
-
1:20
This is something you'll see throughout this course.
-
1:23
One of the purposes of objects is to combine data and
-
1:27
the methods that are closely tied to the data together in one elegant package.
-
1:32
Now that we've learned how to model an object using attributes and behaviors,
-
1:37
we can go on to learn some of the core principles of object-oriented programming.
-
1:41
This is where it gets really interesting.
You need to sign up for Treehouse in order to download course files.
Sign up