Java – Interface variables

Java – Interface variables 2017-08-09T12:13:42+00:00

Java interface variables :

One can declare variable as object references that uses an interface rather than a class type.

When you call a method through one of these references, the correct version will be called based on the actual instance of the interface being referred to.


Output :
Area of Circle is : 329.89625

Here variable ac is declared to be of the interface type AreaCal,

it was assigned an instance of circle. Although ac can be used to access the areacalculation() method,

it cannot access any other members of the client class. An interface reference variable only has knowledge of the method declared by its interface declaration.

Prev Next