&&&&&&&&&&&&&&&&&&& Example demonstrating the use of packages. * Class1.java defined in package1. * Class2.java defined in package2. * Class3.java defined in package2.package3. * Class1.java defined in package4. * PackageExample.java Driver for package example &&&&&&&&&&&&&&&&&&&&& ~~~~~~~~~~~~~~~~~~~~~ Class1.java defined in package1. ~~~~~~~~~~~~~~~~~~~~~ package package1; ***************** public class Class1 { public static void printInfo() { System.out.println("This is Class1 in package1."); } } &&&&&&&&&&&&&&&&&&&&& ~~~~~~~~~~~~~~~~~~~~~ Class2.java defined in package2. ~~~~~~~~~~~~~~~~~~~~~ package package2; $$$$$$$$$$$$$$$$ public class Class2 { public static void printInfo() { System.out.println("This is Class2 in package2."); } } &&&&&&&&&&&&&&&&&&&&&& ~~~~~~~~~~~~~~~~~~~~~~ Class3.java defined in package2.package3 ~~~~~~~~~~~~~~~~~~~~~~ package package2.package3; @@@@@@@@@@@@@@@@@@@@@@@@@ public class Class3 { public static void printInfo() { System.out.println("This is Class3 in " + "package2.package3."); } } &&&&&&&&&&&&&&&&&&&&&&&&& ~~~~~~~~~~~~~~~~~~~~~~~~~ Class1.java defined in package4. ~~~~~~~~~~~~~~~~~~~~~~~~~ package package4; @@@@@@@@@@@@@@@@ public class Class1 { public static void printInfo() { System.out.println("This is Class1 in package4."); } } &&&&&&&&&&&&&&&&&&&&&&&&&& ~~~~~~~~~~~~~~~~~~~~~~~~~~ PackageExample.java Driver for package example. ~~~~~~~~~~~~~~~~~~~~~~~~~~ import package1.*; import package2.Class2; import package2.package3.*; *************************** public class PackageExample { public static void main(String[] args) { Class1.printInfo(); Class2.printInfo(); Class3.printInfo(); package4.Class1.printInfo(); } } ****************************
Aug 29