Dalam Java 9, bolehkah kita menggunakan kaedah persendirian dalam antara muka?
Aug 25, 2023 pm 12:33 PM
Ya, memandangkan Java9 anda boleh menggunakan kaedah peribadi dalam antara muka.
Contoh
interface MyInterface { public abstract void demo(); public default void defaultMethod() { privateMethod(); staticPrivateMethod(); System.out.println("This is a default method of the interface"); } public static void staticMethod() { staticPrivateMethod(); System.out.println("This is a static method of the interface"); } private void privateMethod(){ System.out.println("This is a private method of the interface"); } private static void staticPrivateMethod(){ System.out.println("This is a static private method of the interface"); } } public class InterfaceMethodsExample implements MyInterface { public void demo() { System.out.println("Implementation of the demo method"); } public static void main(String[] args){ InterfaceMethodsExample obj = new InterfaceMethodsExample(); obj.defaultMethod(); obj.demo(); MyInterface.staticMethod(); } }
Output
This is a private method of the interface This is a static private method of the interface This is a default method of the interface Implementation of the demo method This is a static private method of the interface This is a static method of the interface
Atas ialah kandungan terperinci Dalam Java 9, bolehkah kita menggunakan kaedah persendirian dalam antara muka?. Untuk maklumat lanjut, sila ikut artikel berkaitan lain di laman web China PHP!
Kenyataan
Artikel ini dikembalikan pada:tutorialspoint. Jika ada pelanggaran, sila hubungi admin@php.cn Padam

Alat AI Hot

Undresser.AI Undress
Apl berkuasa AI untuk mencipta foto bogel yang realistik

AI Clothes Remover
Alat AI dalam talian untuk mengeluarkan pakaian daripada foto.

Undress AI Tool
Gambar buka pakaian secara percuma

Clothoff.io
Penyingkiran pakaian AI

AI Hentai Generator
Menjana ai hentai secara percuma.

Artikel Panas
R.E.P.O. Kristal tenaga dijelaskan dan apa yang mereka lakukan (kristal kuning)
1 bulan yang laluBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Tetapan grafik terbaik
1 bulan yang laluBy尊渡假赌尊渡假赌尊渡假赌
Assassin's Creed Shadows: Penyelesaian Riddle Seashell
3 minggu yang laluByDDD
Apa yang Baru di Windows 11 KB5054979 & Cara Memperbaiki Masalah Kemas Kini
2 minggu yang laluByDDD
Akan R.E.P.O. Ada Crossplay?
1 bulan yang laluBy尊渡假赌尊渡假赌尊渡假赌

Alat panas

PhpStorm versi Mac
Alat pembangunan bersepadu PHP profesional terkini (2018.2.1).

Penyesuai Pelayan SAP NetWeaver untuk Eclipse
Integrasikan Eclipse dengan pelayan aplikasi SAP NetWeaver.

SublimeText3 versi Inggeris
Disyorkan: Versi Win, menyokong gesaan kod!

Muat turun versi mac editor Atom
Editor sumber terbuka yang paling popular

Dreamweaver Mac版
Alat pembangunan web visual