Basic classes app
The generals who will be using our app will need more than one Soldier
object. In the app 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 very own instance variables.
You can get the completed code for this example in the code download. It is in the Chapter 10/Basic Classes
folder. But it is most useful to read on to create your own working example.
Create a project with the Empty Activity template. Call the application Basic
Classes
. Now we will create a new class called Soldier
:
- Right-click the
com.yourdomain.basicclasses
(or whatever your package name is) folder in the project explorer window. - Select New | Java Class.
- In the Name: field, type
Soldier
and press the Enter key.
The new class is created for us with a code template ready to put our implementation within, just as the next code shows...