Interface

package interface_class;
interface A {
void work1_Administration();
}
interface AB extends A {
void work2_Examination();
void work3_Class_Performance();
}
class secretary implements AB {
@Override                                                              //here we r overriding that method
public void work1_Administration() {
System.out.println(" Here work of administration is done & we have done that");
}
@Override
public void work2_Examination() {
System.out.println("Here work of Examination is done & we have done that");
}
@Override
public void work3_Class_Performance() {
System.out.println("Here class performance is analysed is done & we have done that");
}
}
public class Interface_class {
public static void main(String[] args) {
secretary ob = new secretary();
System.out.println("Give details of administration work");
ob.work1_Administration();
System.out.println("Give details of Examination work");
ob.work2_Examination();
System.out.println("Give details of class performance of all students");
ob.work3_Class_Performance();
}
}

               OUTPUT

Give details of administration work
Here work of administration is done & we have done that
Give details of Examination work
Here work of Examination is done & we have done that
Give details of class performance of all students
Here class performance is analysed is done & we have done that

                         EXPLANATION

In an interface, we use interface class, where methods are defined we can also make one or more interface classes to define method separately but that must be inherited by extend keyword.
After defining, we make a class (not the main class)
which need to inherit interface class by use of implement keyword where methods are doing their required work (here all methods need to be declared )
Now we make the main class (under whole project main class) and by making an object of the class(where methods doing work) we call all methods . This is an interface.

No comments:

Post a Comment