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 trial

Java Java Objects Meet Objects Add a Constructor

Justin Townsend
Justin Townsend
4,720 Points

Java noob

yeah i'm stuck, I don't exactly know what initialization is.

GoKart.java
class GoKart {
  private String color = "red";

  public GoKart(String color){
  this.color = color;
  }

  public String getColor() {
    return color;
  }

}

1 Answer

Tonnie Fanadez
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Tonnie Fanadez
UX Design Techdegree Graduate 22,796 Points

Hi there,

Congrats for passing part one and part two of the challenge; you should now consider yourself an upcoming Java Master!

Initialization is just assigning a value to an Object using a single = sign. Before initialization objects have null value for Strings or default values such as 0 for ints or false for booleans.

In this challenge the value of color is assigned or set to "red" using "=" sign in the field definition. To remove the initialization from the field definition you just need to declare the color but without setting it to red.

See the below code:

//before removing the initialization
private String color = "red";

//after removing the assignment 

private String color;