Click here to watch in Youtube :
https://www.youtube.com/watch?v=IfI7n6pV_4A&list=UUhwKlOVR041tngjerWxVccw
Person.java
Student.java
https://www.youtube.com/watch?v=IfI7n6pV_4A&list=UUhwKlOVR041tngjerWxVccw
Person.java
public interface Person { public void walk(); }
public class Student implements Person { private String name; public String getName() { return name; } public void setName(String name) { this.name = name; } @Override public void walk() { System.out.println(name + " is Walking..."); } }
public class StudentTest { public static void main(String[] args) throws InterruptedException { Person johnReferenceVariable = getPerson("John"); johnReferenceVariable.walk(); System.out.println("--------------------------------"); Person peterReferenceVariable = getPerson("Peter"); peterReferenceVariable.walk(); } /* * You also can use interface names as return types. In this case, the * object returned must implement the specified interface. */ public static Person getPerson(String name) { Student student = new Student(); student.setName(name); return student; } }
John is Walking... -------------------------------- Peter is Walking...
https://sites.google.com/site/javaee4321/java/MethodDemoReturnInterfaceApp.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/MethodDemoReturnInterfaceApp
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/68054fa19b88e552162495a83ba964283753af15/BasicJava/MethodDemoReturnInterfaceApp/?at=master
See also:
No comments:
Post a Comment