Interfaces

Description:

Interfaces: an interface is a contract between class and the outside world. A class promises to provide the behavior published by the interface when it implements an interface.

Implements: A class uses the implements keyword to implement an interface.

overriding: feature that allows a subclass class to provide a specific implementation of a method that is already provided by one of its superclasses

When to use: Interfaces are used to give more flexablity in deciding which classes will have ahich functionality.

Exmaple:

Interface:

public interface Zoan {
  
 public void animalTransformation();
}

Interface:

public interface Paramecia {
    
public void useAbility();
}

Interface:

public interface Logia {
    
public void elementalTransformation();
    
public void useElementalAbility();
}

Class:

public class DevilFruit implements Paramecia{
    
public String name;

    DevilFruit(String name){
        
this.name = name;
    }
    @Override
    
public void useAbility() {
        System.
out.println("Uses " + name + " devil fruit ability");
    }
}

Main class:

public class Main {
  
 public static void main(String[] args) {
        DevilFruit
gumgum = new DevilFruit("Gum Gum");
        
gumgum.useAbility();
    }

}

Results:

Uses Gum Gum Devil Fruit ability

Challenge Problem