In java we have using interface because java doesn’t supports multiple inheritance. Interface in java is the concept which is other option to use concept of multiple inheritance by using java interface example. In the case of Interface example in java we have permission to access the other class by using interface in java. This is simple and easy to learn example of inheritance in java. Interface java example contains simple interface n it is access through the class.
Interface in java a reference of interface type can be refer to object of a class that implements the interface. In java interface example class can implements more than one interface. The following program is example of interface in java.
Program for Java Interface Example
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
interface Info { // start of the program for interface in java static final String language = "CodeCreator"; public void display(); } class SimpleInterface implements Info { public static void main(String []args) { SimpleInterface obj = new SimpleInterface(); obj.display(); } // Defining method declared in interface java example public void display() { System.out.println(language + " is awesome"); } } // End of example of interface in java. |