Java interface static methods

Опубликовано: 02 Май 2017
на канале: kudvenkat
7,989
50

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.
   / @aarvikitchen5572  

package com.training.java;

public interface Interviewer {

int maxInterviewPerWeek = 3;

void interview();

static void scheduleMeeting(int hrs) {
System.out.println("Booked room for " + hrs + "hrs");
}

}


package com.training.java;

public class Manager implements Interviewer {

@Override
public void interview() {
System.out.println("I am Manager, I am hiring for my team");
}

}

package com.training.java;

public class Program {

public static void main(String[] args) {

Interviewer interviwer = new Manager();
Interviewer.scheduleMeeting(2);
interviwer.interview();

}

}

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


На этой странице сайта вы можете посмотреть видео онлайн Java interface static methods длительностью часов минут секунд в хорошем качестве, которое загрузил пользователь kudvenkat 02 Май 2017, поделитесь ссылкой с друзьями и знакомыми, на youtube это видео уже посмотрели 7,989 раз и оно понравилось 50 зрителям. Приятного просмотра!