Answers for "interfaces java when to use"

1

interfaces are used as

It is used to achieve total abstraction.
 Since java does not support multiple inheritance in case of class, but by using interface it can achieve multiple inheritance .
 It is also used to achieve loose coupling.
Posted by: Guest on June-08-2021
1

interface in java

In many cases, it is more important to know what an object can do,instead of 
how it does what it does. This is a reason why interfaces are commonly used for
declaring a type of variable.
 interface : DrawingTool : a tool can draw
 interface DrawingTool {
    void draw(Curve curve);
}
DrawingTool pencil = new Pencil();
DrawingTool brush = new Brush();
Both Pencil and brush class should implement draw method
Posted by: Guest on January-28-2022

Code answers related to "Java"

Java Answers by Framework

Browse Popular Code Answers by Language