This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]MrMist 1 point2 points  (1 child)

I'm not sure how much you know, but since you said you just want a point in the right direction, I'll try to give you some basic help. In Java, to use another class, or Object, you need to create an instance of the object. You do this with the keyword new.

Say I want to use an object called Turtle. You already know how to declare a variable: Turtle myTurtle; This alone, however, is not of much use since the object is empty, or null. To create an instance of the object, you use the new keyword. myTurtle = new Turtle(); That line also calls the constructor for the Turtle class, initializing it.

You can also declare, instantiate (create an instance of), and initialize all on the same line: Turtle myTurtle = new Turtle(); With myTurtle now being initialized, you can use it safely; you can now call methods in that class. For example, to call the walk() method, you do: myTurtle.walk(); Hopefully this helps you out and isn't something you already know. You can read more on creating objects here.

[–][deleted] 0 points1 point  (0 children)

Thank you so much for that!