Hi Joel/Sang,
                    Can u plz provide the complete working example for the
below
Example 3--polymorphic behaviour.

-----
Deepak
On Jan 6, 2013 9:23 PM, "Sang Shin" <[email protected]> wrote:

>  On 1/5/2013 5:53 PM, Joel wrote:
>
> Hi Sang,
>
> In studying the Example 3 (Polymorphic behavior via Java Interface) in the
> Polymorphism lab of Javase, there is an interface class defined as follows:
>
> public interface BookInterface extends ProductInterface {
> public String getPublisher();
> public void setPublisher(String publisher);
> public int getYearPublished();
> public void setYearPublished(int yearPublished);
> }
>
> Why does this class need to extend ProductInterface? I ask because Product
> class already implements ProductInterface. So when you define the Book
> class as:
>
> public class Book extends Product* implements BookInterface*{ ...}
>
> ...it seems as though the Book class inherits ProductInterface twice: once
> from extending Product and again in the BookInterface implementation.
>
>
> Your observation indeed is correct.
>
>
> *I modified the BookInterface definition by removing extends
> ProductInterface and the code runs fine without error.
>
> *So my questions are:
> Is there a reason you extend BookInterface with ProductInterface? Or is
> this simply superfluous coding?
>
>
> The latter. :-)  Apparently the only reason it also extends Product class
> is
> to use a constructor method of the Product class but it does not have
> to as you pointed out.  (The sample code actually uses this
>
> I also found there is some discrenpancy between the document and
> the code sample, which I am in the process of cleaning up.
>
>
> And why does the compiler not complain in Book class that it inherits
> ProductInterface interface twice: once from Product and again from
> BookInterface? Is it Ok to inherit the same abstract methods twice like
> this?
>
>
> Correct.  This is a not compiler error.
>
> -Sang
>
>
> Joel
>  --
> You received this message because you are subscribed to the Google Groups
> "JPassion.com: Java Programming" group.
> To unsubscribe from this group, send email to
> [email protected].
> Visit this group at http://groups.google.com/group/jpassion_java?hl=en-US.
>
>
>
>
>
> --
> -------------------------------------------------------------------
>              Sang Shin, [email protected]
>          http://www.linkedin.com/in/javapassion (Linkedin)
>           http://twitter.com/javapassion (Tweeter)
>             Life is worth living... with Passion!
>
> Free Webinars: "Ruby on Rails", "MySQL", "Java EE 6", "Java Performance"
>              http://javapassion.com/webinars
> ----------------------------------------------------------------------
>
>  --
> You received this message because you are subscribed to the Google Groups
> "JPassion.com: Java Programming" group.
> To unsubscribe from this group, send email to
> [email protected].
> Visit this group at http://groups.google.com/group/jpassion_java?hl=en-US.
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"JPassion.com: Java Programming" group.
To unsubscribe from this group, send email to 
[email protected].
Visit this group at http://groups.google.com/group/jpassion_java?hl=en-US.


Reply via email to