Interface Introduction
Introduce some interface usage in Java. (This is not a comprehensive tutorial!)
What is
// a self-defined interface
interface Animal {
public void eat(); // interface method (does not have a body)
public void moving(); // interface method (does not have a body)
public static void main(String[] args) {
//Animal cat = new Animal(); This is wrong
}
}
public class Cat implements Animal{
@Override
public void eat() {
System.out.println("Cat eats cat food!");
}
@Override
public void moving() {
System.out.println("Cat jumps, runs and walking!");
}
public static void main(String[] args) {
Cat cat = new Cat();
cat.eat();
cat.moving();
}
}Functional Interface
Lambdas in Java 8
Comparator Functional Interface
FrequencySort
Last updated