java筆記 day09 抽象類(二)

2021-07-22 03:39:50 字數 3293 閱讀 8291

2 案例概述:

abstract class teacher

public

teacher(string name,int age)

//get***() and set***()

public string getname()

public

void

setname(string name)

public

intgetage()

public

void

setage(int age)

public

void

show()

//abstract class

public

abstract

void

teach();

}class basicteacher extends teacher

public

void

teach()

}class experimentteacher extends teacher

public

experimentteacher(string name,int age)

public

void

teach()

}class abstractdemo2}/*

running result:

the teacher's name is liu shishi

the teacher's age is 27

basicteacher teaches basic knowledge.

the teacher's name is tangwei

the teacher's age is 28

experimentteacher teaches experiments.

*/

abstract class student

public

student(string name,int age,int sclass)

//get***() and set***()

public string getname()

public

void

setname(string name)

public

intgetage()

public

void

setage(int age)

public

intgetsclass()

public

void

setsclass(int sclass)

public

void

show()

public

abstract

void

learn();

}class basicstudent extends student

public

basicstudent(string name,int age,int sclass)

public

void

learn()

}class experimentstudent extends student

public

experimentstudent(string name,int age,int scalss)

public

void

learn()

}class abstractdemo3}/*

running result:

the student's name is hu ge,age is 22,and class is 1

basicstudents learn basic knowledge.

the student's name is huo gianhua,age is 23,and class is 2

experimentstudents learn experiment knowledge.

*/

**demo:

abstract class employee

public

employee(string name,string id,int wage)

//get*** and set***

public string getname()

public

void

setname(string name)

public string getid()

public

void

setid(string id)

public

intgetwage()

public

void

setwage(int wage)

//abstract class

public

abstract

void

work();

}class programmer extends employee

public

programmer(string name,string id,int wage)

public

void

work()

}class manager extends employee

public

manager(string name,string id,int wage,int bonus)

public

intgetbonus()

public

void

setbonus(int bonus)

public

void

bonus()

public

void

work()

}class abstractdemo4}/*

running result:

xu zj6666666 10000

programmer work.

john zj233333 111111

programmer work.

liu shishi zj999999 15000 120000

manager manages.

*/

從員工**demo中,萬一出現了子類特有的功能時,不能通過多型的方法訪問(這是多型的弊端)。所以只能建立乙個新的物件來訪問該方法。

day09 繼承 super this 抽象類

子父類 現了同名的成員變數時,在子類中需要訪問父類中非私有成員變數時,需要使用 super 關鍵字,修飾父類成員變數,類似於之前學過的 this class father class sonextends father class extendsdemo03 演示結果 fu num 6zi num ...

前端筆記day09

1 完 員列表的刪除功能 姓名姓別 刪除 2 vue的v for語法可以遍歷那些值,分別寫出遍歷不同值的 1 迭代數字 這是第 個p標籤 2 迭代data中的普通物件 3 迭代data中的陣列 3 文字敘述v model和v bind的差別 1 v bind動態繫結指令,預設情況下標籤自帶屬性的值是...

Day09 多型 抽象方法 藉口

今天的內容是基礎班中的乙個重點。多型知識點1.多型的三個前提 繼承關係,方法重寫,父類引用指向子類物件。知識點2 成員變數在多型中 編譯看左邊,執行看左邊。成員方法在多型中 編譯看左邊,執行看右邊。靜態方法在多型中 編譯看左邊,執行看右邊。知識點3 超人的例子,向上轉型和向下轉型 class dem...