- Selenium WebDriver Quick Start Guide
- Pinakin Chaubal
- 143字
- 2021-06-24 18:26:25
Default and static methods in an interface
Up until Java 1.7, it was not possible to define a method inside an interface. Now, 1.8 introduces the default methods through which we can provide implementation for a method inside the interface. Let's see an example of this here:
interface Phone{
void dial();
default void text() {
System.out.println("Texting a message");
}
}
Static methods in Java are those methods that can be invoked without creating an object of a particular class, provided that the static method is in that particular class. In Java 8, static methods can be defined inside an interface, as shown here:
interface Phone {
inx x;
void changeRingtone();
static void text() {
System.out.println("Texting");
}
}
public class PhoneDemo {
public static void main(String[] args) {
Phone.text();
}
}
You can invoke the text() method directly using the name of the interface.
推薦閱讀
- Kubernetes修煉手冊
- Containerization with LXC
- 發布!設計與部署穩定的分布式系統(第2版)
- Mastering Distributed Tracing
- Kubernetes網絡權威指南:基礎、原理與實踐
- VMware Horizon View 6 Desktop Virtualization Cookbook
- 高性能Linux服務器構建實戰:系統安全、故障排查、自動化運維與集群架構
- Windows Phone應用程序開發
- 混沌工程實戰:手把手教你實現系統穩定性
- Python基礎教程(第3版)
- Linux內核觀測技術BPF
- 完美應用RHEL 8
- NetDevOps入門與實踐
- Heroku Cloud Application Development
- Linux系統管理初學者指南:基于CentOS 7.6