An interface can be considered as the blueprint of a class. Methods and variables are provided in an interface and its implementations are done in a class. Till java 7 no method body remained in an interface. An instance of the interface cannot be created, unlike the abstract methods.
Properties of an Interface :
Some of the common properties are as follows:
- All methods of an interface are public static and final by default.
- Mechanism of abstraction in Java can be achieved using abstraction.
- The instance of an interface cannot be created, unlike the abstract class.
- Till Java 7 method bodies were not provided in an interface.
- Since Java 8 default and static methods can be provided in an interface.
The format for using interface:
Interfaces are declared using interface keyword. All the methods in an interface are public, static and final by default due to which total it provided abstraction in Java.
interface interfaceName{ /* code data */ } |
Changes in Java 8:
Since Java 8 one can declare static and default methods in an interface. Discussion regarding this change will be done in the separate tutorial.
☛ Next >> Mouse Pointer Random Movement In Java
Nowadays in some office, it is required to stay on your desk and work for offi...
No comments:
Post a Comment