Tuesday, 12 January 2016

Java Tutorial : Default method in Interface


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 
Person.java
interface Person
{
    
    void walk();
    
    default void sayHello()
    {
        System.out.println("default Hello...");
    }
}
Student.java
public class Student implements Person
{

    @Override
    public void walk()
    {
        System.out.println("Student Walks slowly ..");
    }

}
Employee.java
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");
        
    }

}
InterfaceTest.java
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();
    }

}
Output
Student Walks slowly ..
default Hello...
----------------------
Employee Walks slowly ..
Hello by Employee
Click the below link to download the code:
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:

  • All JavaEE Viedos Playlist
  • All JavaEE Viedos
  • All JAVA EE Links
  • Servlets Tutorial
  • All Design Patterns Links
  • JDBC Tutorial
  • Java Collection Framework Tutorial
  • JAVA Tutorial
  • No comments:

    Post a Comment

    Google+ Followers

    Google+ Badge