Basic classes mini-app
The hypothetical real-time strategy (RTS) game we are writing will need more than one Soldier
object. In our game that we are about to build we will instantiate and use multiple objects. We will also demonstrate using the dot operator on variables and methods to show that different objects have their own instance variables contained in their own memory slot.
You can get the completed code for this example in the download bundle. It is in the chapter 8/Basic Classes
folder. Or read on to create your own working example from scratch.
Create a new project and call the application BasicClasses
. Choose the Empty Activity template. Call the Activity RTSActivity
. As usual, we don't need the Generate Layout File or Backwards Compatibility options. It doesn't really matter too much as we won't be returning to this project after this short exercise.
Creating your first class
After creating the new project we create a new class called Soldier
. Select File | New | Java Class. You...