A method can pretty much return anything.

Let say you have a triangle, a circle and a square.
All of them have their own classes.
But lets all say that they inherit from a Shape Interface.
Following me?
You can supply the Interface instead of the object class for the return 
type; if you expect all three to be returned but don't know which one will.

You follow that?


- ShapeInterface
- Class = Triangle, Cirlce and Square (all inherit from the ShapeInterface)
- ShapeInterface getSides() = will return the sides of a Triangle, 
Circle or Square (or any other objects that inherit the ShapeInterface). 
Now which one is returned is based off what called it.

Some times you will see this: getSides(ShapeInterface shape){}
This will return the shape that is passed into it, as long as it 
inherits from the ShapeInterface and there is another rule but I forgot. 
I need to study up on the basics...

I hope this helps...
Stephen





nn roh wrote:
> Hi all,
>
> I am trying to do the homework , i didnt get this line :
>
> AddressInterface   getAddress();     how can a method return an 
> interface ? can any one elaborate ..
>
>
> Thanks,
> Nada
> -- 
> 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 

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