继承 :5、程序设计 类:汽车类 属性:排量(outPut),颜色(color) 行为:驾驶(drive)
生活随笔
收集整理的這篇文章主要介紹了
继承 :5、程序设计 类:汽车类 属性:排量(outPut),颜色(color) 行为:驾驶(drive)
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
package HomeWork;
/*5、程序設(shè)計
類:汽車類
屬性:排量(outPut),顏色(color) ? ? ? 行為:駕駛(drive)
類:大眾(DasAuto) 繼承自 汽車類 ? ? ? ? ? ? ? ?屬性: 型號(kind)
需求:
1. 所有的類都要寫有參的構(gòu)造方法
2. 實例化一個大眾車的對象 cc , 在路上駕駛*/
public class Test_04 {
public static void main(String[] args) {
DasAuto cc = new DasAuto();
cc.DasAuto("45", "白色","Jeep");
cc.run();
}
}
class Car {
String outPut;
String color;
// public void Car(String outPut, String color) {
// this.outPut = outPut;
// this.color = color;
// }
public void drive() {
System.out.println("排量:" + outPut + "/顏色:" + color + "/在路上駕駛");
}
}
class DasAuto extends Car {
private String kind;
public void DasAuto(String outPut,String color,String kind) {
super.outPut= outPut;
super.color = color;
this.kind = kind;
}
public void run() {
System.out.println("型號:" + kind);
drive();
}
}
/*5、程序設(shè)計
類:汽車類
屬性:排量(outPut),顏色(color) ? ? ? 行為:駕駛(drive)
類:大眾(DasAuto) 繼承自 汽車類 ? ? ? ? ? ? ? ?屬性: 型號(kind)
需求:
1. 所有的類都要寫有參的構(gòu)造方法
2. 實例化一個大眾車的對象 cc , 在路上駕駛*/
public class Test_04 {
public static void main(String[] args) {
DasAuto cc = new DasAuto();
cc.DasAuto("45", "白色","Jeep");
cc.run();
}
}
class Car {
String outPut;
String color;
// public void Car(String outPut, String color) {
// this.outPut = outPut;
// this.color = color;
// }
public void drive() {
System.out.println("排量:" + outPut + "/顏色:" + color + "/在路上駕駛");
}
}
class DasAuto extends Car {
private String kind;
public void DasAuto(String outPut,String color,String kind) {
super.outPut= outPut;
super.color = color;
this.kind = kind;
}
public void run() {
System.out.println("型號:" + kind);
drive();
}
}
總結(jié)
以上是生活随笔為你收集整理的继承 :5、程序设计 类:汽车类 属性:排量(outPut),颜色(color) 行为:驾驶(drive)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 5.【练习题】构造方法与重载
- 下一篇: 继承练习 :开发一个系统时 需要对员工进