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 on the GitHub repo. 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 choose the Empty Activity template. Call the application Basic Classes
. The details don'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 will create a new class called Soldier
. Select File | New | Java Class. You will see the following dialog box: