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) Harnessing the Power of Objects Methods and Constants

Mahvish Irfan
Mahvish Irfan
449 Points

Error when creating new object

Why can't I create a new (pd) object?

Ryan Ruscett
Ryan Ruscett
23,309 Points

Not sure what you are asking here. Can you provide some code of what you are trying to do that does not work?

1 Answer

Grigorij Schleifer
Grigorij Schleifer
10,365 Points

Mahvish,

to create an object in Java you need to use the word "new", the name of the class (the object is created of) and parenthesis with arguments (if the class has defined such arguments). If you look how to create a GoKart object it should look like this:

GoKart gokart = new GoKart();
// gokart is the name ob the object from the GoKart class
// it takes no arguments (parenthesiss is empty

GoKart gokart = new GoKart("Red");
//  this is an object of the GoKart class too
// that takes a String argument "Red" that represents a color

Makes sense?

Greg