Click here to watch in Youtube :
https://www.youtube.com/watch?v=C3vR6hOa_rk&list=UUhwKlOVR041tngjerWxVccw
Click the below Image to Enlarge
Java Tutorial : Default method in Interface |
Java Tutorial : Default method in Interface |
Java Tutorial : Default method in Interface |
Java Tutorial : Default method in Interface |
Java Tutorial : Default method in Interface |
interface Person { void walk(); default void sayHello() { System.out.println("default Hello..."); } }
public class Student implements Person { @Override public void walk() { System.out.println("Student Walks slowly .."); } }
public class Employee implements Person { @Override public void walk() { System.out.println("Employee Walks slowly .."); } @Override public void sayHello() { System.out.println("Hello by Employee"); } }
public class InterfaceTest { public static void main(String[] args) { Person personStudentRef = new Student(); personStudentRef.walk(); personStudentRef.sayHello(); System.out.println("----------------------"); Person personEmployeeRef = new Employee(); personEmployeeRef.walk(); personEmployeeRef.sayHello(); } }
Student Walks slowly .. default Hello... ---------------------- Employee Walks slowly .. Hello by Employee
https://sites.google.com/site/javaee4321/java/InterfaceDemo-DefaultMethod-App.zip?attredirects=0&d=1
Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/InterfaceDemo-DefaultMethod-App
Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/d3069ae3fffccb0c6ba4336662b6a2619d880c61/BasicJava/InterfaceDemo-DefaultMethod-App/?at=master
See also:
No comments:
Post a Comment