Sunday, 11 August 2013

How To Create Interface in java

An interface not a GUI interface that's the public interface using the java keyword interface.A java interface solves the multiple inheritance problem by giving you much of the polymorphic benefits of multiple inheritance.The subclass must implements the method so at run time the JVM is not confused.In an interface all the methods are abstract.Declaring methods that one or more classes are expected to implement.

Here is the program:


interface example{                                      //Creating the interface 
public void says();

}

public class interfaces implements example{               //Implement the interface in class
public void says(){
System.out.println("hello world");
}

public static void main(String arg[]){
interfaces gg = new interfaces();
gg.says();

}



Output of the program:

Like the Post? Do share with your Friends.

No comments:

Post a Comment

IconIconIconFollow Me on Pinterest

Blogger news

Blogroll

What's Hot