Hi tselvi,
You* cannot return an interface *but you *can return an object from one
class implementing the interface*

See again this text and try to understand the fact that you cannot
instantiate "interface objects", they are abstract, I have completed with *
red* to explain better.
        // You can assign the object instance from class implementing
interface to
        // AnotherInterfaceExample type.
        AnotherInterfaceExample anotherinterfaceexample1 = person1;
from Code-3.12: Modified Main.java
in this page
http://www.javapassion.com/handsonlabs/javainterface/index.html#Exercise_3

Probably you should write something like this

public AddressInterface getAddress() {
   return new AddressImpl();//this is the class implementing the interface,
                                          //so you can return this instead
AddressInterface
//sure, you must return an object AddressImpl from the exercise, probably,
//and not an empty one, but I think you figured already
  }

-----------------------------------------------------------------------------------------------------------------
Yes, I see now. You have commented this code

*AddressImpl address = new AddressImpl();*
Well, remove the comment it and write this

public AddressInterface getAddress() {
   return address;//this is the class implementing the interface,
                          //so you can return this instead AddressInterface
  }

*And yes, you must read these
*http://java.sun.com/docs/books/tutorial/java/IandI/abstract.html
http://java.sun.com/docs/books/tutorial/java/IandI/index.html


Best regards,
Vasile Braileanu

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