Java: Interface

This entry is part 50 of 54 in the series Learn Java

Just like a class, an interface is a template for creating objects.

Unlike an ordinary class, however, an interface cannot be instantiated. It simply defines a set of methods that Java classes can implement.

To implement an interface, you use the implements keyword after the class declaration.

A class can implement multiple interfaces.

package javaapplication43;

public class Music {

    interface LiveMusic {
        int live();

    static class Rock implements LiveMusic {

        protected int ls;

        public Rock(int l) {
   = l;

        public int yearly() {
            return ls * 52;

        public int live() {
            return ls;

    public static void main(String[] args) {

        Rock r = new Rock(5);



Series Navigation<< Java: A simpler abstract class example
Java: @Override >>

Leave a comment

Leave a Reply