欧美一区二区三区老妇人-欧美做爰猛烈大尺度电-99久久夜色精品国产亚洲a-亚洲福利视频一区二区

汽車抽象類java代碼 用java編寫汽車類

java中怎么具體使用抽象類和接口???

//繼承抽象類Car并實現(xiàn)接口Gasoline

成都創(chuàng)新互聯(lián)是一家從事企業(yè)網(wǎng)站建設(shè)、成都網(wǎng)站建設(shè)、成都網(wǎng)站制作、行業(yè)門戶網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計制作的專業(yè)網(wǎng)站制作公司,擁有經(jīng)驗豐富的網(wǎng)站建設(shè)工程師和網(wǎng)頁設(shè)計人員,具備各種規(guī)模與類型網(wǎng)站建設(shè)的實力,在網(wǎng)站建設(shè)領(lǐng)域樹立了自己獨特的設(shè)計風(fēng)格。自公司成立以來曾獨立設(shè)計制作的站點成百上千家。

class MyCar extends Car implements Gasoline{

//定義一個變量模擬當(dāng)前檔位,如1,2,3,4,5,

public int nowShift;

//無參構(gòu)造方法,默認(rèn)設(shè)置相關(guān)屬性

public MyCar(){

this.color=Color.red;

this.gearNum=5;

this.tiretype="BridgeStone185ST";

this.engine=(float)1598.5;

}

//自己創(chuàng)建車時指定相關(guān)屬性

public MyCar(Color c,int gearNum,String tiretype,float engine){

this.gearNum=gearNum;

this.color=c;

this.tiretype=tiretype;

this.engine=engine;

}

public void shiftgear(){

//簡單模擬循環(huán)檔,每次調(diào)用時檔位加1,加滿后歸零

nowShift++;

if(nowShift=5)

nowShift=0;

}

public void brake(){

nowShift=0;

System.out.println("正在剎車...");

}

public void aircon(){

System.out.println("冷氣已經(jīng)打開");

}

public void headlight(){

System.out.println("大燈打開...");

}

public void refuel(){

System.out.println("轎車燃料為:"+FUEL);

}

public void equipment(){

System.out.println("轎車顏色:"+color+" "+"排擋數(shù):"+gearNum+"\n"+"輪胎型號:"+tiretype+" "+"尾氣排量:"+engine+" "+"轎車燃料:"+FUEL);

}

public static void main(String[]a){

new MyCar().equipment();

}

}

main()方法里只測試了自定義的equitment()方法,其他的和他一樣調(diào)用,如果你需要的話、希望對你有幫助

java代碼題,要能編譯得出結(jié)果啊!

public abstract class Vehicle {

protected int Wheel;

protected int Weight;

public Vehicle(int wheel,int weight){

}

public abstract void Speak();

}

public interface Moveable {

double MoveSpeed();

}

public class Car extends Vehicle implements Moveable{

public Car(){

super(4,1000);

super.Weight = 1000;

super.Wheel = 4;

}

public void Speak() {

System.out.println("Car speak");

}

public double MoveSpeed() {

return 250;

}

}

public class Truck extends Vehicle implements Moveable{

public Truck() {

super(4,2000);

super.Weight = 2000;

super.Wheel = 4;

}

public void Speak() {

System.out.println("Truck speak");

}

public double MoveSpeed() {

return 450;

}

}

public class TestVehicle {

/**

* @param args

*/

public static void main(String[] args) {

// TODO Auto-generated method stub

Vehicle car = new Car();

System.out.println("Wheel number: "+car.Wheel+" Weight is: "+car.Weight);

car.Speak();

Car c = (Car)car;

System.out.println("Top speed: "+c.MoveSpeed());

Vehicle truck = new Truck();

System.out.println("Wheel number: "+truck.Wheel+" Weight is: "+truck.Weight);

truck.Speak();

Truck t = (Truck)truck;

System.out.println("Top speed: "+t.MoveSpeed());

}

}

用java創(chuàng)建一個汽車類(Car),為其定義兩個屬性:顏色和型號,為該類創(chuàng)建兩個構(gòu)造方法

如下:

public class Car {

private String brandName ; // 汽車牌子

private int color; // 顏色 0:紅 1:黃 2:蘭 ...

public Car( String brandName, int color ){

this.brandName = brandName;

this.color = color;

}

public void move( String direction, int meters ){

System.out.println("牌子為"+ brandName + "的汽車向"+ direction + "移動了"+meters+"米.");

}

public static void main(String[] args){

Car car = new Car( "BMW", 1 );

car.move("東北", 100 );

}

介紹

Java是一門面向?qū)ο缶幊陶Z言,不僅吸收了C++語言的各種優(yōu)點,還摒棄了C++里難以理解的多繼承、指針等概念,因此Java語言具有功能強大和簡單易用兩個特征。

Java語言作為靜態(tài)面向?qū)ο缶幊陶Z言的代表,極好地實現(xiàn)了面向?qū)ο罄碚摚试S程序員以優(yōu)雅的思維方式進行復(fù)雜的編程。

java編程 抽象類: 創(chuàng)建一個Vehicle類并將它聲明為抽象類

public abstract class Vehicle{

public String NoOfWheels();

}

public class Car extends Vehicle{

public String NoOfWheels(){

return "四輪車";

}

}

public class Motorbike extends Vehicle{

public String NoOfWheels(){

return "雙輪車";

}

}

public class Test{

public static void main(String[] args){

Vehicle car =new Car();

Vehicle motorbike=new Motorbike();

System.out.println(car.NoOfWheels());

System.out.println(motorbike.NoOfWheels());

}

}

Java考試編程,小汽車定義成抽象類,成員方法定義成抽象方法,重寫實現(xiàn)抽象方法,怎么用子類實現(xiàn)抽象

//file1

package?com.car;

public?abstract?class?Car?{

private?String?name;

private?String?color;

public?abstract?String?getType();

public?String?getName()?{

return?name;

}

public?void?setName(String?name)?{

this.name?=?name;

}

public?String?getColor()?{

return?color;

}

public?void?setColor(String?color)?{

this.color?=?color;

}?

}

//file2

package?com.car;

public?class?BMWCar?extends?Car?{

private?String?type;

public?BMWCar(String?name,?String?color)?{

setName(name);

setColor(color);

this.type="BMW";

}

@Override

public?String?getType()?{

return?type;

}

public?static?void?main(String[]?args)?{

Car?car?=?new?BMWCar("baoma",?"white");

System.out.println(car.getType());

}

}

java程序,抽象類實現(xiàn),求具體代碼

package test;

/**

*

* @author JinnL

*父類抽象類

*/

public abstract class Car {

//轉(zhuǎn)彎

abstract void turn();

//啟動

abstract void start();

void what(){

System.out.println("this is "+this.getClass().getSimpleName());

}

public static void main(String[] args) {

/**

* 方法入口

*/

Car[] cars ={new Bicycle(),new Automobile(),new GasAutomobile(),new DieselAutomobile()};

for (Car car : cars) {

car.start();

}

}

}

class Bicycle extends Car{

@Override

void turn() {

System.out.println("this is "+this.getClass().getSimpleName());

}

@Override

void start() {

System.out.println("this is "+this.getClass().getSimpleName());

}

void what(){

}

}

class Automobile extends Car{

@Override

void turn() {

System.out.println("this is "+this.getClass().getSimpleName());

}

@Override

void start() {

System.out.println("this is "+this.getClass().getSimpleName());

}

}

class GasAutomobile extends Automobile{

//重寫start turn

@Override

void turn() {

System.out.println("this is "+this.getClass().getSimpleName());

}

@Override

void start() {

System.out.println("this is "+this.getClass().getSimpleName());

}

}

class DieselAutomobile extends Automobile{

@Override

void start() {

System.out.println("this is "+this.getClass().getSimpleName());

}

void what(){

System.out.println("this is "+this.getClass().getSimpleName());

}

}

當(dāng)前文章:汽車抽象類java代碼 用java編寫汽車類
URL鏈接:http://chinadenli.net/article30/hjiepo.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供全網(wǎng)營銷推廣網(wǎng)頁設(shè)計公司網(wǎng)站導(dǎo)航網(wǎng)站收錄網(wǎng)站內(nèi)鏈靜態(tài)網(wǎng)站

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

搜索引擎優(yōu)化