Herencia Patos

Programa que demuestra el uso de la herencia e implementación de interfaces.


Clase principal

public class Duck
{
 
    public void display()
    {
        System.out.println("Se Muestra en pato");
    }
    public void swing()
    {
        System.out.println("El pato nada");
    }
}

Interfaz #1 Quackable

public interface Quackable
{
    public void quack();
}

Interfaz #2 Flyable

public interface Flyable
{
 public void fly();
}

Subclases generadas por la herencia de la clase Duck y las interfaces


Clase Mallord_Duck

public class Mallord_Duck extends Duck implements Quackable, Flyable 
{
    public void quack()
        {
          System.out.println("El pato grazna Grave");
        }
    public void fly()
     {
         System.out.println("El pato vuela alto");  
        }
 
    public static void main( String args[] ) {
        Mallord_Duck me = new Mallord_Duck();
        me.display();
        me.swing();
        me.quack();
        me.fly();
    }      
}

Clase RedHead_Duck

public class RedHead_Duck extends Duck implements Quackable, Flyable 
{
        public static void main( String args[] ) {
        RedHead_Duck me = new RedHead_Duck();
        me.display();
        me.swing();
        me.quack();
        me.fly();
    }
    public void quack()
        {
           System.out.println("El pato grazna agudo");   
        }
    public void fly()
     {
         System.out.println("El pato vuela medio");  
        }
}

Clase Rubber_Duck

public class Rubber_Duck extends Duck implements Quackable 
{
    public static void main( String args[] ) {
        Rubber_Duck me= new Rubber_Duck();
        me.display();
        me.swing();
        me.quack();
    }
    public void quack()
        {
           System.out.println("El pato grazna agudo");   
        }
}

Clase Wood_Duck

public class Wood_Duck extends Duck
{
    public static void main( String args[] ) {
        Wood_Duck me= new Wood_Duck();
        me.display();
        me.swing();
    }
}
Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License