Interference
Suppose class A and B has some abstract method
And child class c want to implement that method by default java doesn’t support multiple
inheritance , this can be achieved using interference
in abstract class at least you can define a method but in interface you cannot define method
suppose we have a child method display and we cannot create obj for interface but we can create
reference
Here [Link]() will work and [Link]() not work as display doesn’t belong to B class , here I am
restricting user form using display .This is the use of interface
A obj = new B()
Every method in your interface is by default public and abstract and we don’t have to mention it
you cannot create instance for interface Abc
we are using anonymous inner class
We are removing the boiler plate code
-> for belongs to mentioning , this is called lambda function
if there is a single statement we can remove curly braces
as opp to what we have discussed earlier we can also define method in interface using default
keyword while defining method .
multiple inheritance is supported in java using interface but you should not define the same method
in both the parent classes or else it will throw an error
here class will have more importance than interface
as static method no need to create object
The interface without any method declaration is called marker interface.
Why it is needed
Now we want to assign permission to class DEMO to print hello we don’t want every one to access it
now we are creating a interface p with no declaration and implementing class DEMO with p .
And create and obj DEMO