inheritance - In java, if I call, from a subclass, a superclass method that calls an overriden method, which class' method will be called? -
say have super class:
public class mysuperclass { protected void myprmethod() { //do... } public void mypumethod() { myprmethod(); } }
and sub class:
public class mysubclass extends mesuperclass { public mysubclass() {} @override protected void myprmethod() { //do instead... } }
then main:
mysubclass mysubclass = new mysubclass (); mysubclass.mypumethod();
which myprmethod mysubclass.mypumethod() call?
edit: got downvoted thrice already. cannot try since not @ home, though knowing answer right me designing part in program making.
because method myprmethod()
overridden in subclass, subclass implementation called.
the actual method gets called depends on object on gets called.
Comments
Post a Comment