Happy Diwali
happy diwali

Saturday, 12 April 2014

interface

Inteface  :-
The interface is a mechanism to achieve full abstraction in java. There can be only abstract methods in the interface. It is used to achieve fully abstraction and multiple inheritance in Java.
Example :
interface A
{
// some methods
// some body      
}
Use Interface :-
·         It is used to achieve fully abstraction.
·         By interface, we can support the functionality of multiple inheritance.
·         It can be used to achieve loose coupling.
Marker Interface : -
An interface that have no member is known as marker or tagged interface. For example: Serializable, Cloneable, Remote etc. They are used to provide some essential information to the JVM so that JVM may perform some useful operation
Ex : :
interface D
{
//no stmts its like just emty
}
Important Points :
·         Inside interface all methods by defult abstract and public methods
·         Inside interface all data members are public static final
Sample points on Interface :
interface  F
{
// variables are possible
          static int i;
          int j;
// methods Declaration
          void test11();
          void test();
// static methods are not possible
static void test1();
// Methods Implementations are not posssible
          static void test1()
          {
                  
          }
// Blocks are not possible
          static
          {
                   System.out.println("hi static");
          }
          {
                   System.out.println("hi");
          }
// abstract methods declaration are  possible
          abstract void tet2();
// abstrct method implementation not possible       
          abstract void test9()
          {
          }
// object creatipon not possible
                   F f1=new F();
// inside interface we cant keep constructor
          F()
          {
                   System.out.println("F()");
          }
//inside interface we can keep defult inner class
          class D
          {
                  
          }
// private inner classes not possible
private class R
{
          }
}
// final interface not possible
          final interface Gt
          {
          // some body
          }
interface R extends F
{
          void test2()
          {
                  
          }
}
         

public class A implements F,R
{

          public static void main(String[] args)
          {

                   abstractA a1=new abstractA();
                   System.out.println(i);

          }

void tet2() {
                   // TODO Auto-generated method stub
                  
          }

public void test2()
{
          // TODO Auto-generated method stub
         
}

public void test11()
{
          //some implementation
         
}

public void test()
{
          //somebody
         
}
public void test1()
{
          // some body
         
}
public void test9()
{
          // method implementation
         
}


}

No comments:

Post a Comment

happy diwali
happy diwali