Tuesday, 12 January 2016

Java Tutorial : Interfaces in Java


Click here to watch in Youtube :
https://www.youtube.com/watch?v=F2dFIuzVq_Y&list=UUhwKlOVR041tngjerWxVccw

Click the below Image to Enlarge
Java Tutorial : Interfaces in Java 
Java Tutorial : Interfaces in Java 
Java Tutorial : Interfaces in Java 
Person.java
interface Person
{
    /*
     * By default variable declared in interface is  public static final
     * (i.e. constant)
     */
    int numberOflegs = 2;
    /*
     * Method signatures have no braces and are terminated 
     * with a semicolon.
     * 
     * By default method declared in interface is public abstract.
     * 
     */
    void walk();
}
Student.java
/*
 * Student class  implements the Person interface
 * and provides implementation of methods defined in the
 * Person Interface.
 */

public class Student implements Person
{

    private String name;

    public Student(String name)
    {
        this.name = name;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    @Override
    public void walk()
    {
        System.out.println(name + " Walks slowly with "+numberOflegs + " legs");

    }

}
InterfaceTest.java
public class InterfaceTest
{

    public static void main(String[] args)
    {
        Person personRef = new Student("Peter");
        personRef.walk();
    }

}
Output
Peter Walks slowly with 2 legs
Click the below link to download the code:
https://sites.google.com/site/javaee4321/java/Interfaces-In-Java-App.zip?attredirects=0&d=1

Github Link:
https://github.com/ramram43210/Java/tree/master/BasicJava/Interfaces-In-Java-App

Bitbucket Link:
https://bitbucket.org/ramram43210/java/src/d3069ae3fffccb0c6ba4336662b6a2619d880c61/BasicJava/Interfaces-In-Java-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