i have a Java assignment and I would like to find out if I am currently on the right track...
The problem is that I am to create a new class name Tester and it stated that I do not need any instance variables nor constructors. Besides this class, I have 4 other class which is Product class, Lineitem class, Inventory class and money class.
Next I am to add a method: private static void addTestItems(inventory theInventory).
This method is to allow me to add four different type of items to the inventory. For each, I will need to create a product object and then create a Lineitem object containing that product follow by using a addItem(), a method which i have declared in the Inventory class, to add the product object.
The method is private as it is just a helper for another main method: public static void test() In this method, I will use this method to print out some output stating the product that was added into the inventory.
What I manage to research is that in such class, I do not need to declare instance variable and constructor. Source: Answer #2 in http://www.allinterview.com/showanswers/62694.html.
However, what I would like to know is that if I am able to create a static product object in this method. If not, how should I go about declaring the product object to be added into the Inventory class?
In addition to my curiosity, by not declaring instance variables and constructors and going straight to static methods, does this mean that this is a static class? Does anyone have a good example of a static class or static method in regards or is very similar to what I am facing?
By the way, I am using BlueJ to do my assignment. I would like to thank everyone hwo read or help me with this problem And if you find this question to be a lousy one please comment and let me know how I can improve on it. By the way.
class Outer { int x ; static class AStaticClass { } class ANormalClass { void meth ( ) { Outer.this.x=5; } } }