Hello,hiran is very right.
for your code it will be
IN THE PERSON CLASS:
AddressInterface addres= new AddressImpl();
AddressInterface gatAddress(){
return addres;
}
and as you did you can set the fields of the addres object threw the main
method.
On Sat, Sep 5, 2009 at 8:08 PM, Hiran Dias <[email protected]> wrote:
>
> Hi,
>
> You can create an Object from AddressImpl class type of AddressInterface
> inside the Person class.
>
> Then it can set and return the Object.
>
> eg:
> AddressInterface pa=new AddressImpl();
>
> public Person() // Constructor
> {
>
> this.pa.setStreetNumber(streetNumber);
> this.pa.setStreetName(streetName);
> this.pa.setCountry(country);
>
> }
>
>
> public AddresInterface getAddres()
> {
> return pa;
> }
>
>
> Cheers!
> Hiran
>
>
>
>
> On Sat, Sep 5, 2009 at 8:20 PM, Tomasz Klekner <[email protected]> wrote:
>
>> Hello, I need help on the homework:
>>
>>
>> - Write an interface called MyOwnInterface, which has the following
>> method
>> - AddressInterface getAddress();
>> - The AddressInterface is a Java interface that has the following
>> methods.
>> - int getStreetNumber();
>> - void setStreetNumber(int streetNumber);
>> - String getStreetName();
>> - void setStreetName(String streetName);
>> - String getCountry();
>> - void setCountry(String country);
>> - Write AddressImpl class that implements AddressInterface
>> - Make the Person class to implement MyOwnInterface.
>> - Initialize a Person object with proper data and display it.
>>
>> This is my code:
>>
>> package PersonMultipleInterfaces;
>>
>> public interface *MyOwnInterface *
>> {
>> AddresInterface getAddres();
>> }
>>
>> -------------------------------------------------------------------------------------------------------------------
>>
>> package PersonMultipleInterfaces;
>>
>> public interface* AddresInterface*
>> {
>> int getStreetNumber();
>> void setStreetNumber(int streetNumber);
>>
>> String getStreetName();
>> void setStreetName(String streetName);
>>
>> String getCountry();
>> void setCountry(String country);
>> }
>>
>> -------------------------------------------------------------------------------------------------------------------
>>
>> package PersonMultipleInterfaces;
>>
>> public class *AddressImpl* implements AddresInterface
>> {
>> int streetNumber;
>> String streetName;
>> String country;
>>
>> public AddressImpl(int streetNumber, String streetName, String
>> country)
>> {
>> this.streetNumber = streetNumber;
>> this.streetName = streetName;
>> this.country = country;
>> }
>>
>> public int getStreetNumber()
>> {
>> return streetNumber;
>> }
>>
>> public void setStreetNumber(int streetNumber)
>> {
>> this.streetNumber = streetNumber;
>> }
>>
>> public String getStreetName()
>> {
>> return streetName;
>> }
>>
>> public void setStreetName(String streetName)
>> {
>> this.streetName = streetName;
>> }
>>
>> public String getCountry()
>> {
>> return country;
>> }
>>
>> public void setCountry(String country)
>> {
>> this.country = country;
>> }
>> }
>>
>> -------------------------------------------------------------------------------------------------------------------------------------
>>
>> package PersonMultipleInterfaces;
>>
>> public class *GetPersonMultipleInterfaces*
>> {
>> public static void *main*(String[] args)
>> {
>> Person Tomek = new Person();
>>
>> Tomek.getAddres().setCountry("Poland");
>> Tomek.getAddres().setStreetName("Kasztelanska");
>> Tomek.getAddres().setStreetNumber(100);
>>
>> System.out.println("The county name is: " +
>> Tomek.getAddres().getCountry());
>> System.out.println("The addres id: " +
>> Tomek.getAddres().getStreetName());
>> System.out.println("The street number is: " +
>> Tomek.getAddres().getStreetNumber());
>> }
>> }
>>
>> ---------------------------------------------------------------------------------------------------------------------------------------
>>
>> package PersonMultipleInterfaces;
>>
>> public class *Person* implements MyOwnInterface
>> {
>> int streetNumber;
>> String streetName;
>> String country;
>>
>> AddresInterface addres;
>>
>> public Person()
>> {}
>>
>> public AddresInterface getAddres()
>> {
>> * ???????????????????????????* <----------- hiere is the problem
>> }
>> }
>>
>> I'm implementing the MyOwnInterface to the Person class but I don't know
>> how to get to the methods implemented in the AddressInterface interface.
>> Please someone explain it to me, i'll be very gratefull.
>>
>>
>>
>
> >
>
--
Abbas Zaini
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---