Posts

Showing posts with the label Interface

Program to implement the following Multiple Inheritance using interface

In  multiple inheritance  there are several super classes for a subclass. Java does not support Multiple inheritance. To achieve multiple inheritance in Java you have to use interface. The syntax for it is given below: interface <interface-name> { // variable declarations // Method declarations (no implementation) } The  implements  keyword is used to for implementing interface and  extends  keyword is used to extend the class. The syntax for extending class and implementing interface is: class <subclass-name> extends <superclass-name> implements <interface-name> { // Body of subclass } In this program, we have created an interface  Exam  which has one method  percent_cal( )  without implementation (body). Then we declare the class  Student  having data members  name, roll_no, marks1, marks2  and one method  display( ) . Finally we extend the  Student ...