oop - java interface and child class -


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

Popular posts from this blog

angularjs - Showing an empty as first option in select tag -

qt - Change color of QGraphicsView rubber band -

c++ - Visible files in the "Projects" View of the Qt Creator IDE if using the CMake build system -