学习班长编写作业

做一个GPSCar类,要求继承Car类,并实现GPS接口;
要求:
1.GPS定义getLocation()方法;
2.Car定义name,speed成员变量 并实现 getCar()方法输出车的名字和速度
3.GPSCar类继承Car并实现GPS接口并重写getLocation(),
返回车的坐标(GPSCar.speed,GPSCar.speed).

重写Car的getCar()方法,除了输出父类的getCar()而且输出getLocation(),


package com.kitsoft.day4;


public class Car{

private String name;

private int speed;




public void getCar(){

System.out.println(this.name+":"+this.speed);

}




public String getName() {
return name;
}




public void setName(String name) {
this.name = name;
}




public int getSpeed() {
return speed;
}




public void setSpeed(int speed) {
this.speed = speed;
}












}


package com.kitsoft.day4;


public class CarTest {


public static void main(String[] args){

GPSCar car = new GPSCar();
car.setName("BMW");
car.setSpeed(200);

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

}

}


package com.kitsoft.day4;


public interface GPS {


public void getLocation();


}


package com.kitsoft.day4;


public class GPSCar extends Car implements GPS{



public void getLocation(){

System.out.println("(0,0)");

}

}

学习班长编写作业_第1张图片

你可能感兴趣的:(学习班长编写作业)