最美情侣中文字幕电影,在线麻豆精品传媒,在线网站高清黄,久久黄色视频

歡迎光臨散文網(wǎng) 會(huì)員登陸 & 注冊(cè)

爆笑Java:怪物,老師類(lèi),轉(zhuǎn)型,多態(tài),樂(lè)器,方法this,依據(jù)不同,進(jìn)行相應(yīng),super

2020-03-05 01:20 作者:詩(shī)書(shū)畫(huà)唱  | 我要投稿


package a;


public class fuxi {


public static void main(String[] args) {


guaiwu j = new hongzhu("大紅豬", 520);


guaiwu l = new hongzhu("小紅豬", 1314);


guaiwu c = new she("小蛇", 7758);


guaiwu[] ms = new guaiwu[3];


ms[0] = l;


ms[1] = j;


ms[2] = c;


for (int i = 0; i < ms.length; i++) {


if (ms[i] instanceof hongzhu) {


((hongzhu) ms[i]).ceshih();

((hongzhu) ms[i]).darendefangfah();

}


else if (ms[i] instanceof she) {


((she) ms[i]).ceshis();


((she) ms[i]).darendefangfas();


}


}


}


}


class guaiwu {


public int gongjili;


public String name;


public guaiwu(String name, int gongjili) {


super();


this.name = name;


this.gongjili = gongjili;


}


public void darendefangfa() {


System.out.println(this.name + "打人的方式很秀");


}


}


class hongzhu extends guaiwu {


public hongzhu(String name, int gongjili) {


super(name, gongjili);


}


public void ceshih() {


System.out.println("名字:" + this.name + ",攻擊力:" + this.gongjili);


}


public void darendefangfah() {


System.out.println(this.name + "打人的方式陳獨(dú)秀");


}

}


class she extends guaiwu {


public she(String name, int gongjili) {


super(name, gongjili);


}


public void ceshis() {


System.out.println("名字:" + this.name + ",攻擊力:" + this.gongjili);


}


public void darendefangfas() {


System.out.println(this.name + "打人的方式一枝獨(dú)秀");


}


}



//在main方法中進(jìn)行測(cè)試


package a;


public class fuxi {


public static void main(String[] args) {


yueqi j = new Violin("小提琴A");


yueqi l = new Violin("小提琴B");


yueqi c = new Piano("鋼琴C");


yueqi[] ms = new yueqi[3];


ms[0] = l;


ms[1] = j;


ms[2] = c;


for (int i = 0; i < ms.length; i++) {


if (ms[i] instanceof Violin) {


((Violin) ms[i]).testPlayv();

}


else if (ms[i] instanceof Piano) {


((Piano) ms[i]).testPlayp();


}


}


}


}


class Piano extends yueqi {


public Piano(String name) {


super(name);


}


public void testPlayp() {


System.out.println(this.name + "有想讓人給詩(shī)書(shū)畫(huà)唱投幣的功能,“當(dāng)當(dāng)”的彈奏");


}


}


class Violin extends yueqi {


public Violin(String name) {


super(name);


}


public void testPlayv() {


System.out.println(this.name + "有想讓人給詩(shī)書(shū)畫(huà)唱點(diǎn)贊的功能,“咦咦”的彈奏");


}


}


class yueqi {


public String name;


public yueqi(String name) {


super();


this.name = name;


}


}



//2.請(qǐng)編碼實(shí)現(xiàn)如下需求:

//老師類(lèi)有三個(gè)子類(lèi):Java老師類(lèi)、數(shù)據(jù)庫(kù)老師類(lèi)、DotNet老師類(lèi)

//老師類(lèi)都

//? ? 有屬性:

//? ? ? 姓名、年齡

//? ? 有方法:

//? ? ? 教書(shū)()的方法。

//


//編寫(xiě)一個(gè)考核();的方法,

//? 調(diào)用考核();的方法先打出老師的姓名、年齡。

//? 再調(diào)用教書(shū)()方法。

//在main方法中進(jìn)行測(cè)試。

package a;



public class fuxi {


public static void main(String[] args) {


teacher j = new Javateacher("Java老師A", 19);


teacher l = new DotNetteacher("數(shù)據(jù)庫(kù)老師B", 20);


teacher c = new SQLteacher("DotNet老師C", 21);


teacher[] ms = new teacher[3];


ms[0] = l;


ms[1] = j;


ms[2] = c;


for (int i = 0; i < ms.length; i++) {


if (ms[i] instanceof Javateacher) {

((Javateacher) ms[i]).kaohej();

((Javateacher) ms[i]).jiaoshuj();


}


else if (ms[i] instanceof SQLteacher) {

((SQLteacher) ms[i]).kaohes();


((SQLteacher) ms[i]).jiaoshus();


} else if (ms[i] instanceof DotNetteacher) {

((DotNetteacher) ms[i]).kaohed();



((DotNetteacher) ms[i]).jiaoshud();


}

}


}


}








class Javateacher extends teacher {


public Javateacher(String name, int age) {


super(name, age);


}

public void kaohej() {


System.out.println(this.name + "今年" + this.age + "歲" );


}

public void jiaoshuj() {


System.out.println(this.name + "今年" + this.age + "歲" + ",勤奮教Java的方法");


}


}









class SQLteacher extends teacher {


public SQLteacher(String name, int age) {


super(name, age);


}

public void kaohes() {


System.out.println(this.name + "今年" + this.age + "歲" );


}

public void jiaoshus() {


System.out.println(this.name + "今年" + this.age + "歲" + ",用心教SQL的方法");


}


}






class DotNetteacher extends teacher {


public DotNetteacher(String name, int age) {


super(name, age);


}

public void kaohed() {


System.out.println(this.name + "今年" + this.age + "歲" );


}

public void jiaoshud() {


System.out.println(this.name + "今年" + this.age + "歲"

+ ",幽默風(fēng)趣,教偷懶且高效教DotNet的方法");


}


}







class teacher {


public int age;

public String name;


public teacher(String name, int age) {


super();


this.name = name;


this.age = age;


}

}


爆笑Java:怪物,老師類(lèi),轉(zhuǎn)型,多態(tài),樂(lè)器,方法this,依據(jù)不同,進(jìn)行相應(yīng),super的評(píng)論 (共 條)

分享到微博請(qǐng)遵守國(guó)家法律
黄山市| 安塞县| 永仁县| 通化市| 赤水市| 泌阳县| 平顺县| 时尚| 莒南县| 永平县| 广河县| 苏尼特左旗| 余庆县| 章丘市| 永登县| 从化市| 清远市| 梁河县| 成都市| 土默特左旗| 辰溪县| 横山县| 庆安县| 明水县| 卫辉市| 孟州市| 盘山县| 萨嘎县| 沾化县| 淳化县| 海宁市| 金门县| 鄄城县| 县级市| 嘉义县| 漳浦县| 尉氏县| 新安县| 柏乡县| 七台河市| 祥云县|