Spaces:
Running
Running
| Once an object has been created by calling a constructor, the information content of the object | |
| can be observed and modified through the public OPERATIONS it provides. | |
| For example, as we know, a list has a public method add, which can be used to add an element to the list: | |
| ArrayList<Double> measurements = new ArrayList<>(); | |
| measurements.add(2.5); | |
| measurements.add(14.0); | |
| measurements.add(-2.75); | |
| System.out.println(measurements); | |
| Program outputs: | |
| [2.5, 14.0, -2.75] | |
| Changing the data content of one object does not change the data content of other objects of the same class. | |
| Objects are therefore INDEPENDENT ENTITIES. | |
| When we add one element to a list, the other lists of the same class do not change. | |
| ArrayList<Double> measurements1 = new ArrayList<>(); | |
| ArrayList<Double> measurements2 = new ArrayList<>(); | |
| measurements1.add(2.5); | |
| measurements1.add(14.0); | |
| measurements1.add(-2.75); | |
| measurements2.add(0.25); | |
| measurements2.add(0.75); | |
| System.out.println(measurements1); | |
| System.out.println(measurements2); | |
| Program outputs: | |
| [2.5, 14.0, -2.75] | |
| [0.25, 0.75] | |