JAVA--關於接口的簡單實用

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();
		
		
	}

}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章