Java interface static methods

preview_player
Показать описание
In this tutorial, we are learning about Java interfaces and their static methods. Prior to Java 8, one would create separate class to hold the helper and utility classes. For example : Collections is a utility class that holds all the static methods to be used with List and Collection interfaces. With static methods in Java, one could simply add such methods to Java interfaces. Here is the code used in this tutorial

Healthy diet is very important both for the body and mind. If you like Aarvi Kitchen recipes, please support by sharing, subscribing and liking our YouTube channel. Hope you can help.

public interface Interviewer {

int maxInterviewPerWeek = 3;

void interview();

static void scheduleMeeting(int hrs) {
}

}

public class Manager implements Interviewer {

@Override
public void interview() {
}

}

public class Program {

public static void main(String[] args) {

Interviewer interviwer = new Manager();

}

}

Java Interfaces vs Classes
1. Both are reference types
2. Both can contain constant, method signatures, default methods, static methods and nested types
3. Both define implementation for default methods and static methods

Interfaces cannot be instantiated, rather they can only be extended by other interfaces or implemented by classes
Рекомендации по теме
Комментарии
Автор

Can i declare static method without body in interface?

sowmyapagidimarri
Автор

sir please reply for uploading SSRS video series

yogeshwargoswami
Автор

How did you use Manager class's interface on Program class, without extending the Manager class in Program class???

tushartripathi
Автор

Why do static methods get invoked directly from their class names and not through an object or instance of the class?

TheINTERLECT
join shbcf.ru