Last active
October 22, 2020 18:22
-
-
Save viveknaskar/4c0e5d25d75c841548cb4c14ba83aeeb to your computer and use it in GitHub Desktop.
Default Method in Interface Example in Java 8
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
package com.viveknaskar; | |
// Class implementing the interface | |
public class DefaultMethodExample implements DefaultMethodInterface { | |
@Override | |
public void abstractMethod() { | |
System.out.println("Hello from abstract method"); | |
} | |
public static void main(String[] args) { | |
DefaultMethodExample dm = new DefaultMethodExample(); | |
dm.abstractMethod(); | |
dm.defaultMethod(); | |
} | |
} | |
interface DefaultMethodInterface { | |
// Abstract method | |
void abstractMethod(); | |
// Default method having method body | |
default void defaultMethod() { | |
System.out.println("Hello, I am coming from default method in Interface"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment