Lakhyadeep Sen’s Post

Interfaces in Java can also extend other interfaces. This allows one interface to build on top of another and combine multiple behaviours. Things that became clear : • an interface can extend one or more interfaces • the new interface inherits all the method declarations from the parent interfaces • any class implementing the child interface must provide implementations for all inherited methods • this helps organize related behaviours into structured layers • it also supports building more complex systems while keeping interfaces modular A simple example helps illustrate this idea : interface ICalculator { void add(int a, int b); void sub(int a, int b); } interface IAdvancedCalculator extends ICalculator { void mul(int a, int b); void div(int a, int b); } class CalculatorImpl implements IAdvancedCalculator { public void add(int a, int b) { System.out.println(a + b); } public void sub(int a, int b) { System.out.println(a - b); } public void mul(int a, int b) { System.out.println(a * b); } public void div(int a, int b) { System.out.println(a / b); } } Through this structure, interfaces can be combined and expanded while still maintaining clear rules for the implementing classes. #java #oop #programming #learning #dsajourney

To view or add a comment, sign in

Explore content categories