封裝的簡單例子

2021-08-15 04:48:37 字數 957 閱讀 9395

舉個例子

package com.u1.day0130;

/** * 封裝的演示。

* *@author feng 2023年1月30日下午2:37:59

*/public

class

demo02

public

demo02(string name, int age, string ***)

void demo03()

/*** 那麼還有其他的方法嗎? 說到方法,我們可以在demo02中加上乙個專門的方法。

* 如果不在構造方法中新增的話,還是會出錯。*/}

public

static

void

main(string args)

public

void

judg()

}}

package com.u1.day0130;

import com.sun.org.apache.xerces.internal.util.synchronizedsymboltable;

/** * 乙個錢包!

*@author feng

* 2023年1月30日下午3:10:00

*/public

class

moneypackage

public

void

setmoney(int money) else

}}

package com.u1.day0130;

/** * 賓客類,可以向錢包的主人借錢,並還錢。

*@author feng

* 2023年1月30日下午3:14:50

*/public

class

guest

}

Java封裝的簡單例子

先來個例子看看 public class man public string getname public void setname string name public int getage public void setage int age public class woman public ...

JS 封裝類的例子

res resname function options this.opts extend defaults,options var st new date getmilliseconds var instance this this.allresnameaarray new array this....

封裝與多型例子

1 1 建立一動物類 animal 2 建立三個子類 dog cat pig都繼承於animal 3 為dog新增love 列印我喜歡吃骨頭 4 為cat新增love 列印我喜歡吃小魚 5 為pig新增love 列印我喜歡吃飼料 6 請建立乙個長度為3的動物陣列animal animals new ...