} public static void cityStateZip() { System.out.println("Kensington, Md. } } The previous two programs placed each of the new methods inside the same class as the main method. Program Java0705.java, in Figure 7.5, creates a defined Address class and places the three new methods inside that class instead. Figure 7.5 // Java0705.java // This program demonstrates how to use a second class separate // from the main program class. // This program will not compile, because the <fullName>, <street> // and <cityStateZip> methods are no longer contained in the <Java0704> public class Java0705 { public static void main(String args[]) { fullName(); street(); cityStateZip(); } } class Address { public static void fullName() { System.out.println("Kathy Smith"); } public static void street() { System.out.println("7003 Orleans Court"); } public static void cityStateZip() { System.out.println("Kensington, Md. 20795"); } }
} public static void cityStateZip() { System.out.println("Kensington, Md. } } The previous two programs placed each of the new methods inside the same class as the main method. Program Java0705.java, in Figure 7.5, creates a Address class and places the three new methods inside that class instead. Figure 7.5 // Java0705.java // This program demonstrates how to use a second class separate // from the main program class. // This program will not compile, because the <fullName>, <street> // and <cityStateZip> methods are no longer contained in the <Java0704> public class Java0705 { public static void main(String args[]) { fullName(); street(); cityStateZip(); } } class Address { public static void fullName() { System.out.println("Kathy Smith"); } public static void street() { System.out.println("7003 Orleans Court"); } public static void cityStateZip() { System.out.println("Kensington, Md. 20795"); } } defined
Text07-UserCreatedMethods.docx