The following is an example showing how to use private methods in Java 9 interfaces −
Example
interface my_int{ public abstract void multiply_vals(int a, int b); public default void add_vals(int a, int b){ sub_vals(a, b); System.out.print("Default method result "); System.out.println(a + b); } private void sub_vals(int a, int b){ System.out.print("Private method result "); System.out.println(a - b); } private static void div(int a, int b){ System.out.print(" Private static method result "); System.out.println(a / b); } } public class my_new_int implements my_int{ @Override public void multiply_vals(int a, int b){ System.out.print("Abstract method result "); System.out.println(a * b); } public static void main(String[] args){ my_int in = new my_new_int(); in.multiply_vals(11, 34); in.add_vals(78, 0); } }
Output
Abstract method result 374 Private method result 78 Default method result 78
An interface named 'my_int' is defined, that has an abstract function, without a body. Another The default function is defined to basically add two numbers. Another function called ‘sub_vals’ is defined, which subtracts the two numbers.
Another static function named div is defined that divides the two values. A class named 'my_new_int' implements the previously defined interface. It overrides the function that multiplies values and redefines it. In the main function, an instance of the interface is created, and the 'multiply_vals' function is called by passing specific values. Similarly, the 'add_vals' function is also called by passing specific values. The respective output is displayed on the console.
The above is the detailed content of Private methods in Java 9 interface. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SublimeText3 Chinese version
Chinese version, very easy to use