Interfaces are not prototypes for classes in Java.
In languages such as C and C ++, which are compiled directly into machine code, the compiler must know the nature of any identifier (variable / class / function) before they are referenced anywhere in the program. This means that these languages must know the nature of the identifier in order to generate the output of the machine code that is associated with it.
In simple words, the C ++ compiler needs to know the methods and member of the class before this class is used anywhere in the code. To achieve this, you must define the class in front of the line of code where it is used, or you must at least declare its nature. Declaring only the nature of a function or class creates a 'prototype'.
In Java, an “interface” is something like a class description. This determines which all methods should have a particular class type. Then you can create classes that implement this interface. The main purpose that interfaces serve in java is the possibility that a variable declared as a specific type of interface can contain objects of any class that implements the object.
Vishnuprasad r
source share