Interface in JAVA

Author posted by Jitendra on Posted on under category Categories JAVA and tagged as Tags with 1 Comment on Interface in JAVA

Explains the usage and benefits of interface in JAVA.

Interface & Its Advantage:-

1. If all the methods in the class is abstract then the class is nothing but the interface.

2. We cannot create an object of interface.

3. To implement the interface by child class keyword “implements” is used.

4. Interface is defined by using keyword interface.

5. If a class implements interface but does not implements methods, then the class is abstract class.

6. We can assign the object of class which implements the interface of type of                                                     that interface.

interface Duck
    Void DuckType();
    Void DuckProperty();

class BlackDuck implements Duck
 Public void DuckType()
     System.out.println("Black Duck");

 Public void DuckProperty()
   System.out.println("Swim, Quack  and Fly");

class TestDuck
 Public static void main(String args[])
     BlackDuck obj=new BlackDuck();

Advantages of Interface:-

  • Runtime Polymorphism
  • Contract can be used throughout the application

To know more about inheritance and abstract classes, refer this article.

Related posts

One thought on “Interface in JAVA”

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.