InterviewSolution
| 1. |
Can an Interface extend another Interface? |
|
Answer» An interface in JAVA is a collection of abstract methods. This interface is IMPLEMENTED by a class that abstract methods of the interface. An interface can extend another interface using the extends keyword. In this way, the methods of the parent interface are inherited by the child interface. An example of an interface extending another is given as follows: public interface Department { public void name(); } public interface Finance extends Department { public void expenses(); public void quarterlyReports(); public void income(); } public interface Marketing extends Department { public void onlineBudget(); public void offlineBudget(); }The class that IMPLEMENTS the Finance interface NEEDS to implement 4 methods as there are 3 methods in Finance and it inherits 1 method from Department. Similarly, the class that implements the Marketing interface needs to implement 3 methods as there are 2 methods in Marketing and it inherits 1 method from Department. |
|