Trotter,
I've used Java before, but I when I program (which rarely happens anymore), I use C/C++. However, OOP in C++ is very similar to Java, so I'll be going off of that. The explanation below is might be confusing to you (it took me a while to understand classes/objects etc...), so I suggest that you sit down for 20 minutes or so and carefully/slowly read each word and try to understand it. You've already shown great initiative by searching elsewhere, other than your book. It's something I didn't do
Anyways,
Just to clarify - a class is something that
stores information using variables and
operate on them using
functions.
Now, what you did in your main program was that you created
objects of your classes. For example... takes us humans as an example. The class would be the body - right? What should be inside the body (aka class)? Well... hearts, eyes, brain, legs, arms, shoulders, muscles, etc... Think of these are variables. What functions do we need to perform on ourselves? Well, we need the regulation of our immune system, respiratory system, etc. Think of these human systems as functions of the class (or functions of the human body). Hopefully this should clear up any confusion you might have. This example really helped me when learning.
------------------------------------------------------------
Let's have a look at your code:
InventoryA q = new InventoryA(2, "Notebooks", 15, 0.5);
What you're doing here is
creating a new object. This new object is q.
This is just like creating a new person with the name q... think of someone giving birth and bringing in a new child into the world... you're doing the same thing, sort of
In your first class (not your main program), you defined a function InventoryA that accepts variables into it. In your main program, you're sending the values of:
2
Notebooks
15
0.5
into (respectively)
int _itemNum
String _name
int _units
double _price
when you create it then instantiate it (this is kind of like the official term). So, you create the object q and give it the paramaters of 2, Notebooks, etc. Your new object,
q, has the information you gave it above.
Even though you can't do this in reality, think of this as giving your child attributes when he or she is first born... the color hair you want the child to have, the eye color, weight, height, etc.
This information is now stored in the variables above. Now, once the variables of
int _itemNum, String _name, int _units, double _price are given values,
it will assign them INTO the object's own internal/personal variables, which you have labeled as itemNum
, name, units, price.
In your class InventoryA, the function InventoryA is defined as a constructor. It constructs the object with the specified information. It is good practice to include some sort of parameters, even if you don't have any. For example, in C++, you may have a class and then create an object of the class with no initial parameters... you still should have a constructor in your class.
-undefined