00:01
All right, this question asks us to name two types of methods that you can only add to an interface with java 8 or onwards.
00:11
So, prior to java 8, right, we can only have method declarations in the interface, but from java 8 onwards, there's two different types of things that was introduced.
00:20
The default method and the static method.
00:31
So these two new things, right, so let's start with the default method.
00:34
So what a default method does is it's essentially the default method can be created in an interface.
00:49
So when a class implements the interface, it's not mandatory to provide implementation for the default method of an interface.
00:56
So it's easier to show if i write it.
01:00
So essentially, let's say we have a function or method with, or sorry, we have a function.
01:08
An interface with a default method then it is not necessary it is not is not necessary to provide implementation for the for that method to provide an implementation for that method all right so that's what a default method does and something that's this feature is useful in is it helps extending interfaces with additional methods all you need to do do is provide a default implementation.
01:57
So essentially it helps with extending interfaces with additional methods.
02:22
And java doesn't allow us to extend multiple classes because it will result in a diamond problem, where the compiler doesn't know which superclass method to use.
02:33
With default methods, a diamond problem would happen for interfaces as well.
02:38
Because if a class is implementing both like if a class implementing two different interfaces and it doesn't implement the common default method then the compiler can't decide which one to choose so we won't know what to do so that's one of that's an issue that could come from the default method but one thing that does help with is by making it really easy to add additional methods and extending interfaces so without the fear of breaking implementation classes.
03:10
So without fear of breaking.
03:20
Default methods bridge the difference between interfaces and abstract classes.
03:30
Difference between interfaces and abstract classes...