- 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.
推薦閱讀
- 嵌入式Linux開發技術
- Designing Purpose:Built Drones for Ardupilot Pixhawk 2.1
- Linux系統文件安全實戰全攻略
- Kali Linux滲透測試全流程詳解
- VMware Horizon View 6 Desktop Virtualization Cookbook
- Linux性能優化
- Ganglia系統監控
- 精解Windows8
- 嵌入式Linux應用開發菜鳥進階
- Dreamweaver CS5.5 Mobile and Web Development with HTML5,CSS3,and jQuery
- 細說Linux基礎知識
- NetDevOps入門與實踐
- ElasticSearch Cookbook
- Linux系統最佳實踐工具:命令行技術
- Advanced Infrastructure Penetration Testing