Java 8 Default Method in Interface




Hey guys in this article, you will understand the defining the default in interface which in introduced in Java 8.

Read More:

Since Java 8, we can have method body in interface. But we need to make it default method.

interface Drawable {
	void draw();  
    default void msg(){
    	System.out.println("default method");
    }  
}

class Rectangle implements Drawable{  
    public void draw(){
    	System.out.println("drawing rectangle");
    }  
}

public class TestInterfaceDefault{  
    public static void main(String args[]){  
    	Drawable d = new Rectangle();  
        d.draw();  
        d.msg();  
    }
} 

That’s it for this post, if you like this post, share this with your friends and colleagues or you can share this within your social media platform. Thanks, I will see you in our next post.



Our Best Partners: tabela minutos pagantes fortune tiger casino com depósito de 1 real play fortuna casino review https://luckyjetwins.com/registation/ brite casinot https://luckyjetslots.com/ru/ tiger slot crazy time predictor https://luckyjetwins.com/strategy/ jogo da mina online

Bushan Sirgur

Hey guys, I am Bushan Sirgur from Banglore, India. Currently, I am working as an Associate project in an IT company.

Leave a Reply