Home » Core Java » Interface in Java

Interface in Java


Interface :

1 : Interface in java is declared using keyword interface.
2 : Interface means 100% abstraction.
3 : Interface can not have any concrete method.
4 : All methods declared inside Java Interfaces are implicitly public and abstract
5 : All variables declared inside interface is implicitly public static final variable or  constants. 
6 : In Java its possible for an interface or class  to extend multiple interfaces.
7 : We should use interface when we are not sure of  implementation of  methods in different classes which are     going to implement the interface.

Example : Consider an interface Shape with abstract method area() and variable pi .The sub class Circle implements the interface Shape and overrides area() method.In the main class we created object of subclass and access area() method.

Marker  interface :
 1 : Marker interface in Java is an interface with no field or methods.
 2 : These are used to provide necessary information to the JVM so that JVM may perform some useful operation.
 3 : For example: Serializable, Cloneable etc. 

Leave a comment

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

15 + 13 =