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 (Retired) Meet Objects Creating New Objects

Kamran Ismayilov
Kamran Ismayilov
5,753 Points

Constructor

I do not know what to do else here. In fact I did not get why we using constructor?

Example.java
public class Example {

    public static void main(String[] args) {
        System.out.println("We are going to create a GoKart");
        GoKart goKart = new Gokart("blue");

    }
}

2 Answers

Chase Marchione
Chase Marchione
155,055 Points

Hi Kamran,

Java is case sensitive (meaning uppercase and lowercase characters are interpreted differently by the compiler... thus, a GoKart and a Gokart would be considered two different classes.)

        GoKart goKart = new GoKart("blue");

As for why we use constructors: constructors are used to create (instantiate) new objects using a class as a blueprint for what those objects contain. In this case, our class is GoKart, and we want to create a new object of that class type.

Hope this helps!