oop - java interface and child class -
this question has answer here:
i have next question. have interface
public interface myinterface { blah blah }
and have child:
public class mychild implemets myinterface { blah blah }
what difference between:
mychild child = new mychild();
and
myinterface child = new mychild();
?
your added code snippet -
mychild child = new mychild();
and
myinterface child = new mychild();
in first case child
can contain object of mychild
class. in second case child
(where child myinterface
) can contain object of class implements myinterface
. here can advantage of polymorphism.
Comments
Post a Comment