It is still a bit confusing.

If the Person class contains a interface reference like

public class Person{
      private AddressInterface address;
     .........
     ..........

// and the method
     public AddressInterface getAddress(){
        return address;
    }

then the getAddress method only returns that reference. In the person
class that reference does not point to the AddressImpl class right????

Therefore in the main class

Can it be said that
Person p=new Person();
// Explicit casting
AddressImpl address1=(AddressImpl)p.getAddress();

address1=new AddressImpl();

// and then use the address1 to access get and set methods.

Is the above correct in sense of what is required.
On Sep 5, 12:24 am, Presario 6331RSH HAM <[EMAIL PROTECTED]> wrote:
> To the first question, No. Do not assume AddressImpl address; gets
> used in Person class.
> Person should use private AddressInterface address; in the variables
> list and
>
> // Implement MyOwnInterface method
>     public AddressInterface getAddress() {
>         return address;
>     }
>
> This needs to be public here because you will use it in Main.class.
> And there you will store address data using the AddressImpl.class.
> An instance of AddressInterface.class holds the address data. I know
> it seems confusing that an interface with no variables is able to
> store anything but that is the magic of using interface instances. It
> is still a class and we gave whatever holds the address data that
> classification.
>
> from Main.class
>
> AddressInterface address1 = person1.getAddress();// data = get method
>
> On Sep 4, 2:21 pm, miga <[EMAIL PROTECTED]> wrote:
>
>
>
> > On Sep 4, 8:54 pm, abstract26 <[EMAIL PROTECTED]> wrote:
>
> > > Is it okay to assume that the Person class will contain the
> > > AddressImpl class instance?
> > You don't need this line, otherwise you defeat the purpose of the
> > AddressInterface interface.
>
> > >        AddressImpl address;
>
> > This, yes, that's the implementation of MyOwnInterface, except that it
> > should be public.> // The person class contains a method
>
> > >   AddressInterface getAddress(){
> > >    }
>
> > > }
>
> > > The addressImpl class implements the AddressInterface
> > > where as the
> > > Person class implements MyOwnInterface.
>
> > See above.- Hide quoted text -
>
> - Show quoted text -

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to