public class PackageDataTest
class PackageData
1: // Fig. 8.20: 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: {
7: public static void main( String args[] )
8: {
9: PackageData packageData = new PackageData();
10:
11: // output String representation of packageData
12: System.out.printf( "After instantiation:\n%s\n", packageData );
13:
14: // change package access data in packageData object
15: packageData.number = 77;
16: packageData.string = "Goodbye";
17:
18: // output String representation of packageData
19: System.out.printf( "\nAfter changing values:\n%s\n", packageData );
20: } // end main
21: } // end class PackageDataTest
22:
23: // class with package access instance variables
24: class PackageData
25: {
26: int number; // package-access instance variable
27: String string; // package-access instance variable
28:
29: // constructor
30: public PackageData()
31: {
32: number = 0;
33: string = "Hello";
34: } // end PackageData constructor
35:
36: // return PackageData object String representation
37: public String toString()
38: {
39: return String.format( "number: %d; string: %s", number, string );
40: } // end method toString
41: } // end class PackageData
42:
43:
44: /**************************************************************************
45: * (C) Copyright 1992-2005 by Deitel & Associates, Inc. and *
46: * Pearson Education, Inc. All Rights Reserved. *
47: * *
48: * DISCLAIMER: The authors and publisher of this book have used their *
49: * best efforts in preparing the book. These efforts include the *
50: * development, research, and testing of the theories and programs *
51: * to determine their effectiveness. The authors and publisher make *
52: * no warranty of any kind, expressed or implied, with regard to these *
53: * programs or to the documentation contained in these books. The authors *
54: * and publisher shall not be liable in any event for incidental or *
55: * consequential damages in connection with, or arising out of, the *
56: * furnishing, performance, or use of these programs. *
57: *************************************************************************/