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

}


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