Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialFEI LI
828 PointsThis line... MapLocation mapLocation = new MapLocation(20,20, map)
Can someone explain to me what all those elements above stand for... first, let me show you how I understand this so far .. correct me if I am wrong please MapLocation stands for a method? mapLocation stands for a name of a variable? new stands for creating a new variable in this case
20,20, is the two parameters of the Maplocation I don't know what's the meaning of the "map", why its in the parenthesis with 20,20,
I am confused what this line is used for? Does it mean to create a new variable using MapLocation method?
1 Answer
Steven Parker
231,198 PointsYou got part of it:
-
MapLocation
is an object class -
mapLocation
is the name of the variable being created (you got that one!) -
new
is the keyword indicating that an instance of the class is being created -
MapLocation
is the class again but also the name of the constructor method -
20, 20
are the coordinates of the location being created -
map
is a variable containing the instance of the map object that this new location will refer to
The whole line creates a new variable named "mapLocation" which is an object of the MapLocation class and which represents the point at coordinates {20,20} on the map object stored in the variable "map".
Jamie Wyton
3,011 PointsJamie Wyton
3,011 PointsYour right most of the part, MapLocation is the type of field you are creating, mapLocation is the name of it and the new MapLocation is the constructor method you are using to create it, so the 20, 20 is the x and y points for the location and the map argument is passed on to ensure that 20, 20 is on the map if you look at the constructor.