java 接口调用implements实例

computer代码:

package computer;

import java.util.*;

public class computer {	
	
	public static void main(String args[]){
		Scanner input=new Scanner(System.in);
		USB usb1;
		usb1= new udisk();
		String a=input.nextLine();
		System.out.println(a);
		usb1.iinput(a);
		System.out.println(usb1.output());
	
	}

}

USB代码://为interface文件

package computer;

public interface USB {
			public void iinput(String data);
			
			public String output();
}

udisk代码:

package computer;

public class udisk implements USB{
	String memory;
	public void iinput(String date){
		this.memory=date;
	}
	public String output(){
		return this.memory;
	}
	

}

你可能感兴趣的:(代码)