about me

Wednesday, 3 August 2016

Interface-1

-Interface support dynamic method resolution at run time.

-Interface are similar to multiple inheritance in C++.

-Interface is defined like class.

    Syntax is:

                            <accessibility modifier> interface<interface name> <extends interface clause> //interface header

                                  {

                                         // interface body

                                        <return type method1(parameter)>

                                       <return type method2(parameter)>

                                        <type final var 1=value>

                                       <type final var 1=value>

                                     <nested class declaration>

                                    <nested interface declaration>

                             }

-Name of interface is preceded by keyword interface.

-Method have no bodies. Each class that includes an interface must implements all of the methods.

-Variables in interface are implicitly final and static, so they can not be change by implementing class.

-Variables must also be initialized with a constant value.

-If interface declared as public, then,  all methods and variables are also implicitly public in interface.

-interface does not provide any implementation, and it is  abstract.

-Members(Methods and Variables) declaration can be written in any order in the interface body.

-Methods in interface are abstract and public by default.

-To implement an interface, a class must create the complete set of methods of interface.

-Any number of classes can implement  single interface.

-Any number of interfaces can be implemented by single class.

i.e.

          interface x

       {

              void x(int a);

       }