2018年12月15日 星期六

[Java]_ch8.4_方法傳遞類別變數



[Java]_ch8.4_方法傳遞類別變數



public void compare(人類 human) {

if(this==human)

System.out.println("同一人");

else

System.out.println("不同人");

}

public 人類 compareR(人類 human) {

int m =this.眼+this.耳+this.口+this.鼻;

int n =human.眼+human.耳+human.口+human.鼻;

if(m>n) {

System.out.println("this資料成員較大,眼="+this.眼+" 耳="+this.耳+" 口="+this.口+" 鼻="+this.鼻);

return this;

}else {

System.out.println("human資料成員較大,眼="+human.眼+" 耳="+human.耳+" 口="+human.口+" 鼻="+human.鼻);

return human;

}

}







亞當.compare(王五);

人類 derek=亞當;

derek.compare(亞當);



人類 Jerry=王五.compareR(張三);

王五.compare(Jerry);

沒有留言:

張貼留言

Ether.fi Cash Card 一張所有人必備的加密貨幣信用卡   [Ether.fi Cash Card] : https://www.ether.fi/app/cash/sign-up?ref_code=d27f8523 ------國際交易所------ [Bitg...