Interface

Interface
            Interface methods pure abstract methods.
            All interface methods should be public.we need not declare as public.
                   
             By default behaviour is public all interface methods are implicitly public and abstract and need not to type the public or abstract modifiers
                            
                              Interface methods must not be static.it cannot be marked as strictfp,final or static.

        All variables defined in as interface must be static ,public ,final.Interface declare only constants.


Example

interface Shape {

 public double area();
 public double volume();
}
 
Example With Variables 
 
interface Foo{
        int bar=40;
        void first();
} 

class Main implements Foo{
      public void first()
      {
          bar=70;          /// error here you cant change the variable herer
 
      } 

}

Compiler Declartion In Interface

Example

interface first{

       void second();            // here your declartion like this
       void third();
}


interface first

public abstract void second(); // this is what compiler will take this one as you have declared above
public abstract void third();


All interface methods must be implemented and must be marked as public

Limitations

An interface can extend one or more interfaces.
It cant implement another interfaceor class.
 
Keyword..interface,implements

No comments:

Post a Comment

Loading