... files—PackageDataTest.class and PackageData.class. The compiler places the two .class files in the same directory. You can also place class PackageData (lines 22–30) in a separate source-code file.

Fig. 8.15

 1 // Fig. 8.15: PackageDataTest.java
 2 // Package-access members of a class are accessible by other classes
 3 // in the same package.
 4
 5 public class PackageDataTest {
 6      public static void main(String[] args) {
 7         PackageData packageData = new PackageData();
 8
 9         // output String representation of packageData
10         System.out.printf("After instantiation:%n%s%n", packageData);
11
12         // change package access data in packageData object
13         packageData.number = 77;
14         packageData.string = "Goodbye";
15
16         // output String representation of packageData ...

Get Java How to Program, Early Objects, 11th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.