Types of Interface in Java

Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java

Program 1

//  @FunctionalInterface
//  interface MyInter1
//  {
//    void a1();

//  }
interface First
{
     void a1();
}
interface Second
{
     void a2();
}

class MyClass implements First,Second    // Multiple Inheritance
{
     public void a1()
     {
        System.out.println("Method of First Interface");
     }
     public void a2()
     {
        System.out.println("Method of Second Interface");
     }
}
  class TestTypeInter
  {
      public static void main(String args[])
      {
            MyClass M1=new MyClass();
            M1.a1();
            M1.a2();
     }
  }






/* 
     Normal Interface
     Marker or Markable Interface
     Functional Interface
     Multiple Inhertance Interface
     Single abstract method Interface
*/

// Normal Interface
//   interface MyInter
//   {
//       void display();
//       void show();
//   }
//   class MyClass implements MyInter
//   {
//         public void display()
//         { 
//             System.out.println("This is display method");
//         }
//         public void show()
//         { 
//         }
//   }
// import java.io.*;
// class Student implements Serializable
// {
//         private int rno;
//         private String name;
//         private String course;
//         Student(int rno,String name,String course)
//         {
//               this.rno=rno;
//               this.name=name;
//               this.course=course;
//         }
//         public String toString()
//         {
//               return this.rno + "  " + this.name + "   "+ this.course;
//         }
// }
//   class TestTypeInter
//   {
//       public static void main(String args[])
//       {
//         try
//         {
//         //     Student S1=new Student(101,"Dipesh Gupta","Mtech");
//              File f=new File("d://javadata//student.txt");
//         //     FileOutputStream fos=new FileOutputStream(f);
//         //    ObjectOutputStream oos=new ObjectOutputStream(fos);
//         //    oos.writeObject(S1);
//         //     fos.close();
//               FileInputStream fis=new FileInputStream(f);
//               ObjectInputStream ois=new ObjectInputStream(fis);       
//               Student S=(Student)(ois.readObject());
//               System.out.println(S);
//               ois.close();
//               fis.close();
//         }
//         catch(Exception e)    
//         {
//              System.out.println(e);
//         }
//   //      System.out.println("File Created..........");
//       }
//   }

 

Did you know we work 24x7 to provide you best tutorials
Please encourage us - write a review on Google

courses

TechVidvan Team

TechVidvan Team provides high-quality content & courses on AI, ML, Data Science, Data Engineering, Data Analytics, programming, Python, DSA, Android, Flutter, full stack web dev, MERN, and many latest technology.

Leave a Reply

Your email address will not be published. Required fields are marked *