Skip to content

Instantly share code, notes, and snippets.

@2013techsmarts
Created February 15, 2017 17:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 2013techsmarts/28d9253af6e8f5c68dbb5387c6f6ce36 to your computer and use it in GitHub Desktop.
Save 2013techsmarts/28d9253af6e8f5c68dbb5387c6f6ce36 to your computer and use it in GitHub Desktop.
Demonstration of private methods in Interfaces - Java 9 feature
jshell> public interface Sample {
...> default void doSomeThing(String message) {
...> //Call private method
...> doSomeThing();
...> System.out.println("The deafult interface method!!!");
...>
...> }
...>
...> private void doSomeThing() {
...> System.out.println("Demonstration of interface private methods!!!");
...> }
...> }
| created interface Sample
jshell> public class SampleImpl implements Sample {
...> }
| created class SampleImpl
jshell> Sample s = new SampleImpl();
s ==> SampleImpl@4bec1f0c
jshell> s.doSomeThing("SmartTechie");
Demonstration of interface private methods!!!
The deafult interface method!!!
jshell>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment