How to Use Interface (implements) in Java


In this example we will show how to use interface (implements) in Java.

Source Code

package com.beginner.examples;

interface Animal {
  public void yell(); // interface method
}

class Dog implements Animal { // java interface (implements)
  public void yell() {
    System.out.println("yell");
  }
}

public class DogYell {
  public static void main(String[] args) {
    Dog d = new Dog();
    d.yell();
  }
}

Output:

yell
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments