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.
Comments are closed for "Java interface".
is there other methods then abstract methods? would public, private, protected be another example of methods?
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
[…] 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 […]
[…] start with an interface which creates a blue print for the class which will have decorators. Then implement that interface […]
it is wonderful but give some examples
give some examples sir
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)
MouseListener popupListener=new PopupListener();
PopupListener is class that extends MouseAdapter. Please explain that line. Am I creating object for an interface or class?
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 :)
Why interface can’t be instantiated????
please reply fast..
thnks in advance
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.
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
i have some questions about interface.
plz explain dat can we instantiate an interface?
and
can we create constructor of an interface