做一个GPSCar类,要求继承Car类,并实现GPS接口;
要求:
1.GPS定义getLocation()方法;
2.Car定义name,speed成员变量 并实现 getCar()方法输出车的名字和速度
3.GPSCar类继承Car并实现GPS接口并重写getLocation(),
返回车的坐标(GPSCar.speed,GPSCar.speed).
要求:
1.GPS定义getLocation()方法;
2.Car定义name,speed成员变量 并实现 getCar()方法输出车的名字和速度
3.GPSCar类继承Car并实现GPS接口并重写getLocation(),
返回车的坐标(GPSCar.speed,GPSCar.speed).
重写Car的getCar()方法,除了输出父类的getCar()而且输出getLocation(),
package cn.mashensoft.homework2;
public class GPSCar extends Car implements GPS{
public void getLocation(){
System .out .println(this.speed+","+this.speed);
}
<span style="white-space:pre"> </span>//this表示调用父类的成员变量!
public void getCar(String name , int speed){
super.getCar(name, speed);
this.getLocation();
}
}
<pre name="code" class="java">package cn.mashensoft.homework2;
public interface GPS {
public void getLocation();
}
package cn.mashensoft.homework2;
public class Car {
String name ;
int speed;
public Car() {
super();
// TODO Auto-generated constructor stub
}
public Car(String name, int speed) {
super();
this.name = name;
this.speed = 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;
}
public void getCar(String name , int speed){
System .out .println("车的名字是:"+name+"车的速度为:"+speed);
}
}