Van icon

JAVA INTERFACES

Links


    //INTERFACES <
    /*
    * INTERFACES: An interface is a completely "abstract class" that is used to group related methods with empty bodies:
    * INTERFACE + IMPLEMENTS
    * no se desarrollan los metodos en la interfaz
    * HAY QUE DESARROLLAR LOS METODOS GENERALMENTE @override !! CLASES EVENTS, ACTION LISTENER
    */
    package D_Advanced;

    public class Interfaces {

        public Interfaces() {

            Pig myPig = new Pig();  // Create a Pig object
            myPig.animalSound();
            myPig.sleep();
        }

        // Interface
        interface Animal {
            public void animalSound(); // interface method (does not have a body)
            public void sleep(); // interface method (does not have a body)
        }

    // Pig "implements" the Animal interface
        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");
            }
        }

    }