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:
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:
No comments:
Post a Comment