Accessing Interface Variables in Java

The  variables of an interface are always declared as "final". Final variables are those variables, whose  values are constants and cannot be changed. The class that implements the interface can use the variables as declared in the interface and cannot modify or changed the value of the variable.

Program to implement interfaces

Interface is the prototype of class (means we can declare the functions only)that can be implemented by any number of classes. It is the collection of methods and variables. Methods are only abstract methods means the methods has no statements. We use interface keyword to declare an interface.

Interface

/*An interface is basically a kind of class. The difference is that interface define any abstract methods and final fields(datamember or data functions). Interfaces do not specify any code,we can declare methods and  data fields contain only constant. Therefore, it is the responsibility of the class that implements an interface to define the code for implementation of these meathods.

Interface in Java

 

Java cannot support multiple Inheritance means we cannot create multiple super classes or we can say parents classes or base classes .This is the main reason we can create interface. In interface we can declare function only but not create the body.

 

About Us

Rekha SetiaRekha Setia is a passionate blogger of Extra Computer Notes. if you have any ideas or any request me @