❮ Previous Next ❯

JAVA Interface Introduction



Why Interface

The general form of an interface is

interface InterfaceName
{
fields declarations;
methods declarations;
}
The java compiler adds public and abstract keywords before the interface method and public, static and final keywords before data members.
Example
Interface Demo
{
int x=10;
void show();
}
Here the keyword interface tells that Demo is an interface containing one final field x and one abstract method show().

NOTE:

Compiler automatically converts methods of Interface as public and abstract, and the data members as public, static and final by default.

What we declare
interface Demo
{
     int x=100;
     void print();
}

What the Compiler Understand

interface Demo
{
     public static final int x=100;
     public abstract void print();
}
Let’s see a demo program for better understanding:

Example;

InterfaceExample1.java


package java8s;
interface Demo
{
     void print();
}

class Example2 implements Demo
{
     public void print()
     {
          System.out.println("JAVA means Silan Technology");
     }
}
public class InterfaceExample1 {

     public static void main(String[] args) {
         
          Example2 obj=new Example2();
          obj.print();
         

     }

}

Output
Interface

 

❮ Previous Next ❯



  Tutorials

Popular Links

Contact Us

address Plot No-N6/530,2ND Floor
Nayapalli,Jayadev Vihar
      Bhubaneswar-751015
      Email: info@silantechnology.com
      Phone: 0674-2361252
address
39877, sundale dr, apt#101, Fremont, California 94538, USA
       Phone: +1(262)388-7619

facebook twitter google linked in

© 2018 Silan Technology. All Rights Reserved