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 trialSGT Awesome
480 PointsI am more lost than a blind man in a forest! HELP!
I've watched the video but it's just not clicking. And what purpose do constructors even have?!
public class GoKart {
private String mColor = "red";
public GoKart(String mColor){
mColor = color
}
public String getColor() {
return mColor;
}
}
1 Answer
Michael Hess
24,512 PointsHi SGT Awesome,
There are two things that are really important to understand in an object oriented programming language like Java.
- Classes
- Objects
A class is a blueprint for an object. An object is a thing -- like a goKart, a book or a bicycle.
Constructors helps us build objects. I feel like I may confuse you if I go further, so at this point, this is probably all you really need to know.
You're really close! But, there is a semicolon missing after color. Also the constructor argument should be String color.
Please see the following code:
public class GoKart {
private String mColor = "red";
public GoKart(String color){
mColor = color;
}
public String getColor() {
return mColor;
}
}
If you have any further questions feel free to ask! Hope this helps!
This is a link to Oracle's Java tutorials covering constructors: Providing constructors for your classes
This is a link to Oracle's Java tutorials covering classes Declaring Classes
SGT Awesome
480 PointsSGT Awesome
480 PointsThanks again for saving my bacon! ^_^
Michael Hess
24,512 PointsMichael Hess
24,512 PointsGlad I could help!