interface ComputerCompany {
//該接口有2個功能:String computerName,void printFunction。
public String computerName ();
public void printFunction();
}
interface ComputerWeight {
//該接口中有3個功能:double computrWeight,void printName,double printPrice。
double computrWeight();
void printName();
double printPrice();
}
public class FlashMemory implements ComputerCompany {
double computrWeight(){
double i = 1.33;
if (i>2)
{
return 1.0;
}
else
{
return 2.0;
}
}
public String computerName (){
String s ="sd";
return s;
};
public void printFunction(){
System.out.println("這是訓練接口使用的代碼");
};
}
接下來是測試用的代碼
public class Test {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
FlashMemory f = new FlashMemory();
System.out.println(f.computerName());
System.out.println(f.computrWeight());
f.printFunction();
}
}