Java, .NET, PHP, PYTHON, ANGULAR, .NET, ML, Data Scince, Testing, CI Tutorials in Easy Languages.

"Best Software Training, Internship, Project Development center of Indore India, Helpline 780506-3968"

Interface:-




it is special component of JAVA which will only contain a set of the abstract method. The interface is also called Pure Abstract Class because it is only for data abstraction.


No need to declare any keyword to define abstract, by default all method of interface is public and abstract.

interface Interfacename
{
      datatype identifier=value  //constant with final
      return type methodName();
}

Interface  = Constant + Abstract Method

Advantage of Interface:-

1) Data abstraction:-  we can not create an object of the interface then the actual function can be hidden.


2) Data Contract:-   all methods of an interface must be implemented in class.


3)Multiple Inheritance:-  we can create multiple interfaces and implement into Single Class.

The interface method is null hence it not raise any ambiguity problem.


Interface to Interface extends keyword will be used

Interface to Class implements keyword will be used

Interface Program

interface Area
{
    void triangle();
    void circle();
}
interface Maths
{
    void add();
}


class Calc implements Maths
{
       public void triangle()
       {
       }
      public void circle()
       {

       }
      public void add()
        {

       }
       public static void main(String args[])
       {

       }
}



Interface and Class Example:-

interface Area
{
    void triangle();
    void circle();
}
interface Maths extends Area
{
    void add();
}


class Calc implements  Maths
{
       public void triangle()
       {
       }
      public void circle()
       {

       }
      public void add()
        {

       }
       public static void main(String args[])
       {

       }
}










Post a Comment

If you have any doubt in programming or join online classes then you can contact us by comment .

Previous Post Next Post