/** * @author gtowell Purpose: Nested Class Example */ public class ClassNester { /** * The nested Class */ private class TwoInts { public int intOne; // an integer public int intTwo; // another integer /** Constructor filling the two integers */ public TwoInts(int i1, int i2) { intOne = i1; intTwo = i2; } } /** Array holding up to 100 TwoInts instances */ TwoInts[] tIntsArray = new TwoInts[100]; /** The number of instances in the array */ int aCount = 0; /** * Add a twoInts instance to the array * * @param i1 * @param i2 */ public void addItem(int i1, int i2) { TwoInts ttii = new TwoInts(i1, i2); ttii.intOne += ttii.intTwo; // this is very silly tIntsArray[aCount++] = ttii; } /** * Show the contents of the array */ public void printAll() { for (int i = 0; i < aCount; i++) { System.out.println(tIntsArray[i]); } } public static void main(String[] args) { ClassNester cn = new ClassNester(); cn.addItem(3, 4); cn.addItem(20, 21); cn.printAll(); } }