Chapter 8 Object-Based Programming 417 18 JOptionPane.showMessageDialog( null,
Chapter 8 Object-Based Programming 417 18 JOptionPane.showMessageDialog( null, 19 employee.toString(), “Testing Class Employee”, 20 JOptionPane.INFORMATION_MESSAGE ); 21 22 System.exit( 0 ); 23 } 24 25 } // end class EmployeeTest Date object constructor for date 7/24/1949 Date object constructor for date 3/12/1988 Fig. 8.15 Demonstrating an object with a member object reference (part 2 of 2). 8.12 Package Access When no member access modifier is provided for a method or variable when it is defined in a class, the method or variable is considered to have package access. If your program consists of one class definition, this has no specific effects on the program. However, if your program uses multiple classes from the same package (i.e., a group of related classes), these classes can access each other s package-access methods and data directly through a reference to an object. Performance Tip 8.3 Package access enables objects of different classes to interact without the need for set and get methods that provide access to data, thus eliminating some of the method call overhead. Let us consider a mechanical example of package access. The application of Fig. 8.16 contains two classes the PackageDataTest application class (lines 8 34) and the PackageData class (lines 37 54). In the PackageData class definition, lines 38 39 declare the instance variables number and string with no member access modifiers; therefore, these are package access instance variables. The PackageDataTestapplication s main method creates an instance of the PackageData class (line 13) to demonstrate the ability to modify the PackageData instance variables directly (as shown on lines 20 21). The results of the modification can be seen in the output window. When you compile this program, the compiler produces two separate files a .class file for class PackageData and a .class file for class PackageDataTest. Every Java class has its own .classfile. These two .classfiles are placed in the same directory by the compiler automatically and are considered to be part of the same package (they are certainly related by the fact that they are in the same file). Because they are part of the same package, class PackageDataTest is allowed to modify the package access data of objects of class PackageData. Copyright 1992 2002 by Deitel & Associates, Inc. All Rights Reserved. 7/3/01
Note: If you are looking for cheap and reliable webhost to host and run your mysql application check Vision professional web hosting services