I modified the Person class constructor to pass an instance of
AddressInterface . The main creates an instance of AddressImpl of type
AddressInterface that is passed to the Person instace then I use getAddress
to load another address instance.
package mypersoninterfaceproject;
public class Main {
public static void main(String[] args) {
// Create the data for person1
AddressInterface pAddress1 = new AddressImpl(1011, "Main Street",
"USA");
Person person1 = new Person("Sang", "Shin", pAddress1);
// Trying to print out the data
AddressInterface person1Addr = person1.getAddress();
System.out.println("person1's name is " + person1.getName() );
System.out.println("person1's address is " +
person1Addr.getStreetNumber() + " " +
person1Addr.getStreetName() + " " +
person1Addr.getCountry() );
}
}
This worked.
Did the purpose of the homework was for the student to do this in another
way ?
Jeff
--
You received this message because you are subscribed to the Google Groups
"JPassion.com: Java Programming" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
Visit this group at http://groups.google.com/group/jpassion_java.
For more options, visit https://groups.google.com/d/optout.