Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //基底類別(父類別)
- public class Otaku
- {
- //欄位
- public int weight, height;
- //建構子
- public Point(int weight, int height)
- {
- this.weight = x;
- this.height = y;
- }
- }
- //衍生類別(子類別)
- public class IdolOtaku : Otaku{
- //欄位
- public string oshiMem;
- //建構子
- public IdolOtaku(int weight,int height,string oshiMem) :
- //繼承自父類別的建構子並將所需要的引數傳遞過去
- base(weight,height)
- {
- this.oshiMem = oshiMem;
- }
- }
- //宣告三個實體
- Otaku achan = new Otaku(100, 200);
- IdolOtaku asurin = new IdolOtaku(10, 20, "yukka");
- //可以用基底類別的名稱來宣告變數
- //但new 後面必須使用衍生類別的名稱
- Otaku momoko = new IdolOtaku(10, 20, "nanase");
Add Comment
Please, Sign In to add comment