Implementation of the interface method must be public
Hi All,
I am reading Java the complete Referance Book where I came across a line "When you implement an interface method it must be declare public".
Just wanted to know is this a mendatory thing. I have little nowledge of J2EE but as far as I know when we program servlet we implement
protectedvoid doGet(Param)
Thanks.
> Just wanted to know is this a mendatory thing.
Yes. You can't reduce visibility after inheritance. Wouldn't make sense, does it?
> I have
> little nowledge of J2EE but as far as I know when we
> program servlet we implement
HttpServlet isn't an interface, last I checked, and the doGet() method is protected.
> > Just wanted to know is this a mendatory thing.
>
> Yes. You can't reduce visibility after inheritance.
> Wouldn't make sense, does it?
>
> > I have
> > little nowledge of J2EE but as far as I know when
> we
> > program servlet we implement
>
> HttpServlet isn't an interface, last I checked, and
> the doGet() method is protected.
I was just wondering If the Interface have package private access then the method in the interface are by default package private (Is this correct), So when we implement the interface in the same package we can declare the method as package private or default access this might be perfectly legal.
Please correct me if I am wrong.
> > > Just wanted to know is this a mendatory thing.
> >
> > Yes. You can't reduce visibility after
> inheritance.
> > Wouldn't make sense, does it?
> >
> > > I have
> > > little nowledge of J2EE but as far as I know
> when
> > we
> > > program servlet we implement
> >
> > HttpServlet isn't an interface, last I checked,
> and
> > the doGet() method is protected.
>
> I was just wondering If the Interface have package
> private access then the method in the interface are
> by default package private (Is this correct), So when
> we implement the interface in the same package we can
> declare the method as package private or default
> access this might be perfectly legal.
>
> Please correct me if I am wrong.
You are wrong. Everything declared on an interface is public, whether you declare it to be so or not