0% found this document useful (0 votes)
8 views10 pages

Interference

The document discusses the concept of interfaces in Java, highlighting how they allow for multiple inheritance and the implementation of abstract methods. It explains that interfaces cannot have method implementations by default, but can use default methods and lambda functions to simplify code. Additionally, it mentions marker interfaces, which are used to assign permissions to classes without method declarations.

Uploaded by

Shiva Ram Vemula
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views10 pages

Interference

The document discusses the concept of interfaces in Java, highlighting how they allow for multiple inheritance and the implementation of abstract methods. It explains that interfaces cannot have method implementations by default, but can use default methods and lambda functions to simplify code. Additionally, it mentions marker interfaces, which are used to assign permissions to classes without method declarations.

Uploaded by

Shiva Ram Vemula
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

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 obj.show() will work and obj.display() 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

You might also like