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 |
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 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"); } }
public class InterfaceTest { public static void main(String[] args) { Person personRef = new Student("Peter"); personRef.walk(); } }
Peter Walks slowly with 2 legs
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:
No comments:
Post a Comment