Java interface

A java class containing all the methods as abstract is called an interface. A method that has no implementation and which is expected to be implemented by a subclass is called an abstract method. Java interface can contain constants. When an interface needs to be instantiated it should be implemented by a class and all its abstract methods should be defined. If all the methods are not implemented in the class then it becomes a java abstract class and so cannot be instantiated. Variables declared in a java interface by default is final.

This Abstract and Interface tutorial was added on 23/04/2008.

Comments on "Java interface" Tutorial:

  1. Anonymous says:

    is there other methods then abstract methods? would public, private, protected be another example of methods?

  2. Vishal Pawar says:

    Hello Sir,
    It’s all blogs are great. I have really got amazing information through this blogs would you please add some questions regarding to Struts and Hibernate. It will be really helpful.

    Thanks again for all blogs….

    Regards
    Vishal S. Pawar

  3. […] an adapter is the travel power adapter. American socket and plug are different from British. Their interface are not compatible with one another. British plugs are cylindrical and American plugs are […]

  4. […] start with an interface which creates a blue print for the class which will have decorators. Then implement that interface […]

  5. Anonymous says:

    it is wonderful but give some examples

  6. pavan says:

    give some examples sir

  7. Arun Ruhela says:

    interface I1
    {
    void show();
    void display();
    }
    class A implements I1
    {
    public void show(){System.out.println(“Hi”);}
    public void display(){System.out.println(“Friend”);}
    }
    public static void main(String [] args){
    A o=new A();
    o.show();o.display();
    }
    }

    Probleam: Multiple inheritence concept ignore this case.why interface used? Bcoz declare two methods declare in interface and a class define those methods.if this class remove line Implements I1 then also class just same work .Then this case what benefits of used interface????

    Plz tell me extra benefits of interface used (concept multiple inheritence exclude)

  8. Dinesh says:

    MouseListener popupListener=new PopupListener();

    PopupListener is class that extends MouseAdapter. Please explain that line. Am I creating object for an interface or class?

  9. Anonymous says:

    arun raheja-
    benefit of interface is..
    you are bounding the class blueprint now..if some class is gonna extent interface the that class has to follow the defined patern :)

  10. Ramsimran says:

    Why interface can’t be instantiated????
    please reply fast..
    thnks in advance

  11. rahul says:

    Interfaces are not meant for instantiation.They act as a medium or blueprint for the class.
    Interfaces are used to encode similarities which the classes of various types share, but do not necessarily constitute a class relationship.

  12. Vishal says:

    Joe,
    I love your way of sharing knowledge about Java in simple language. I came across a nice link explaining Interface, so sharing it here.

    http://edn.embarcadero.com/article/30372

  13. pratiksha kaule says:

    i have some questions about interface.

    plz explain dat can we instantiate an interface?
    and
    can we create constructor of an interface

Comments are closed for this "Java interface" tutorial.