Search from 700 + Posts

Feb 22, 2011

Sample Java Program to Implment Java Interfaces

Write a Simple Interface in Java as shown below , and compile it.

package java_testIface;

public interface Java_Interfaces {
  //  public Java_Interfaces() {
    //    super();
   // }
   
  /*public static void main(String[] args){
    System.out.println("This is an Example of Interfaces");
  }*/
 
  public void cust();
  public void item();
  public void price();
  public void order();
   
}



Once Interface is ready , write Java code to implement these Interfaces

package javaSO;

import java_testIface.Java_Interfaces;

public class java_imp_ifaces implements Java_Interfaces {
    public java_imp_ifaces() {
        super();
    }
    //Unless we Implement Methods of Interface System will
    //Prompt a error message.
    public void cust(){
      System.out.println("Get Customer data");
    }
    public void item(){
      System.out.println("Get Item data");
    }
    public void price(){
      System.out.println("Get Price data");
    }
  public void order() {
    System.out.println("Get Order data");
  }
   
public static void main(String[] args) {
  java_imp_ifaces oom = new java_imp_ifaces();
  oom.cust();
  oom.item();
  oom.price();
  oom.order();
                        
}
}
//We always Implement the Interfaces and Extend the Class.

No comments:

Post a Comment