Polymorphism, Java Game Development, Constructors, and Objects

-1 Developer John · September 29, 2014
If you are wondering why I made a huge title for this discussion, it's because I wanted to prevent myself from making several other discussions. First off, I would want to know what objects and constructors are. I've been trying to grip the meaning of them, but can't at most times. Also, Polymorphism confuses me too. Are you just using a for loop instead of importing classes? Lastly, when I become a professional at programming, I would like to start creating my own game. What should I use to create it?


Post a Reply


Oldest  Newest  Rating
+1 Alex Sweps · September 29, 2014
Hi John

Simply put an object is a place where you can store methods for later use. For example, say you want to have a bunch of vehicles in your game that can move forward and back. You could create an object for that vehicle with methods inside it that trigger the code for it move forward. Objects are usually written by creating a new class and naming it Vehicle (Or whatever you want to name it).

An example would be this in side your new class you created called Vehicle:

public class Vehicle{
       public static void moveForward(){
                   System.out.println("Moving the car forwards")

Then to use that object in your game you would create a variable that references it. That reference variable is like the remote control that you can call the objects methods with. In your main class or any other class other than Vehicle you would do this:

Vehicle myVehicleObject = new Vehicle()

Now  myVehicleObject is your remote control. If you want the car to move forward you use your remote control to call the moveForward method.


This would output: "Moving the car forwards"
If you want another car seperate from the one you just created you simply create another reference to it like:

Vehicle anotherVehicle = new Vehicle()

My suggestion would be to practise making a few objects and referencing them before you move onto constructors and polymorphism.
-1 Developer John · October 5, 2014
You should make your problem a new conversation.
-1 gerben b · October 5, 2014
Okay, I've deleted my post here. Just to clean up your thread.
0 Developer John · October 5, 2014
Thank you.
0 Developer John · October 13, 2014
So, whenever you use the return statement, it's for booleans, assigning values, and what else, printing?8-)
  • 1

Java / Android Development


Very popular language used to create desktop applications, website applets, and Android apps.

Bucky Roberts Administrator