On Oct 9, 6:13 pm, DHARMENDRAN GOVIND <[email protected]> wrote: > Dear Sir, > > I am not sure how to return the interface type AddressInterface. > > Steps taken: > 1) created an interface called AddressInterface with these following > methods. > int getStreetNumber(); > void setStreetNumber(int streetNumber); > String getStreetName(); > void setStreetName(String streetName); > String getCountry(); > void setCountry(String country); > > 2) created an class called AddressImpl that implements AddressInterface. > 3) created another interface called MyOwnInterface with method getAddress > that returns AddressInterface. > AddressInterface getAddress(); > 4) modified person class to implement MyOwnInterface and implement method > getAddress. > > Question: How can I return an addressinterface? Exactly as you would return any object: return new Object(param1, param2, ..., paramn);
except that in the case of an interface, you return the implementation of the interface, since an interface cannot be instantiated. That is if the interface is MyInterface, and its implementation is MyImplementationOfMyInterface, you return the latter with the needed parameters, so that the wanted object could be constructed. Michèle Garoche -- To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/javaprogrammingwithpassion?hl=en
