Created
February 15, 2017 17:52
-
-
Save 2013techsmarts/28d9253af6e8f5c68dbb5387c6f6ce36 to your computer and use it in GitHub Desktop.
Demonstration of private methods in Interfaces - Java 9 feature
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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