Default Method Java 8
๐๐๐๐๐ฎ๐ฅ๐ญ ๐ฆ๐๐ญ๐ก๐จ๐
One of the news of JAVA 8 , itโs simply a keyword โdefaultโ added to a method in an interface to make it as default .
๐พ๐๐ ๐๐โ๐ ๐๐ ๐ ๐๐ !?
Sometimes we have many classes implementing same interface A. After a time , we want to add a new method to this interface . The problem we can face is that we should implement this method in all classes implementing this interface , which is a little bit hard (imagine 100 classes ๐ ). Here default keyword comes , in a way that we can create a method with itโs implementation inside an interface ( interfaces support just abstract methods except static and default methods ) .
๐พ๐๐๐ ๐๐๐๐ !? ๐พ๐ ๐๐๐ ๐๐๐ ๐๐๐๐๐๐ ๐๐๐๐๐๐ ๐ , ๐๐ ๐ ๐๐๐ ๐๐๐ ๐๐๐๐ ๐๐๐๐๐ .
No,static methods cannot be overrided , otherwise we can override default methods .
Defaults methods could be called via the instance of the class implementing the interface, static methods could be called directly from the interface without making an instance .
Thanks for reading ๐๐ป