Java method that returns interface type -
as reading java interface, came across following example. know how implement interface. returning interface type in method new me. me understand example? methods in "animal" interface implemented in "categorizeanimals" method? if yes, "animals" array passed interface methods in "categorizeanimals" method?
public class wild { public static interface animal { public list<string> getinvertebrates(); public list<string> getfishes(); public list<string> getamphibians(); public list<string> getreptiles(); } public static animal categorizeanimals(string[] animals) { ....... ....... ....... return null; } }
appreciate reply, much.
very simple solution if have put interface of method then ever class instance returning class has have interface implemented.
public class implementedclass implements interfacename { @override public void sayhi(string hello) { // todo auto-generated method stub } @override public void sayhello() { // todo auto-generated method stub } public interfacename sayhello1() { system.out.println("returning new intance of class implementing interface"); return new implementedclass(); } }
interface
public interface interfacename { public void sayhi(string hello); public void sayhello(); }
Comments
Post a Comment