Open links in new tab
  1. Interfaces in Java - GeeksforGeeks

    • The interface in Java is a mechanism to achieve abstraction. Traditionally, an interface could only have abstract methods (methods without a body) and public, static, and final variables by default. It is used to a… See more

    Relationship Between Class and Interface

    A class can extend another class, and similarly, an interface can extend another interface. However, only a class can implement an interface, and the reverse (an interface im… See more

    GeeksForGeeks
    Difference Between Class and Interface

    Although Class and Interface seem the same there have certain differences between … See more

    GeeksForGeeks
    Java Interfaces Examples

    Let’s consider the example of vehicles like bicycles, cars, bikes, etc they have common functionalities. So we make an interface and put all these common functionalities. And lets Bic… See more

    GeeksForGeeks
    Advantages of Interfaces in Java

    The advantages of using interfaces in Java are as follows: 1. Without bothering about the implementation part, we can achieve the security of the implementation. 2. In Java, multipl… See more

    GeeksForGeeks
    Feedback
     
  1. 123

    An interface in Java is a reference type, similar to a class, that can contain only constants, method signatures, default methods, static methods, and nested types. Interfaces cannot be instantiated—they can only be implemented by classes or extended by other interfaces. The primary purpose of an interface is to define methods that can be implemented by any class from any inheritance tree.

    Implementing Interfaces

    To implement an interface, a class must provide the body of all the methods declared within the interface. Here's a simple example to illustrate how a class can implement an interface:

    interface Animal {
    void animalSound();
    void sleep();
    }

    class Pig implements Animal {
    public void animalSound() {
    // The body of animalSound() is provided here
    System.out.println("The pig says: wee wee");
    }
    public void sleep() {
    // The body of sleep() is provided here
    System.out.println("Zzz");
    }
    }

    class Main {
    public static void main(String[] args) {
    Pig myPig = new Pig(); // Create a Pig object
    myPig.animalSound();
    myPig.sleep();
    }
    }
    Was this helpful?

    See results from:

     
  2. Java Interface - W3Schools

     
  3. Interface in Java - Javatpoint

    WEBLearn what an interface is in Java, how to declare and use it, and how it supports abstraction and multiple inheritance. See examples of interface with default, static and private methods, and marker interface.

  4. Java Interface (With Examples) - Programiz

  5. What Is an Interface? (The Java™ Tutorials - Oracle

  6. Java Interfaces - Baeldung

  7. Interfaces (The Java™ Tutorials > Learning the Java Language ...

  8. Java Interfaces Explained with Examples

    WEBFeb 1, 2020 · Learn what interfaces are in Java, how they differ from classes, and how to use them with examples. Interfaces can define method signatures, default methods, static methods, and multiple inheritance.

  9. Everything you need to know about Interfaces in Java

  10. Guide to Interfaces in Java - Stack Abuse

  11. Some results have been removed