java - Interface implementation access modifier not as expected -
i came across example of interface implementation can't head around, text not having reasoning the answer on here can lend hand.
given interface
interface flyer{ void takeoff(); boolean land(); }
then suppose have implementation follows
class aeroplane implements flyer{ public void takeoff(){ ... } //insert code here return true; } }
the code insert given public boolean land(){
, states following incorrect boolean land(){
why need have public
when interface has defined method package-private
, surely boolean land(){
should implement interface, or have missed something?
"the interface has defined method package-private"
all methods declared in interfaces public definition. there no way around this.
this
interface flyer{ void takeoff(); boolean land(); }
is equivalent this
interface flyer{ public void takeoff(); public boolean land(); }
this illegal:
interface flyer{ private void takeoff(); private boolean land(); }
as this:
interface flyer{ protected void takeoff(); protected boolean land(); }
neither compile.
Comments
Post a Comment