题目是使用接口比较汽车速度的大小
//主类
public class tVehicle extends Vehicle{
public static void main(String[] args) {
// TODO Auto-generated method stub
Vehicle a=new Vehicle();
a.speedup();
Vehicle b=new Vehicle();
b.speedup();
b.speedup();
int a1;
a1=a.speed;
int b1;
b1=b.speed;
compare( a1, b1); }
}
//Vehicle类
public class Vehicle implements Comparable{
int speed=0;
public void speedup() {
speed+=10;
}
public void slowdown() {
speed-=10;
}
public void showinfo() {
System.out.println(speed);
}
public String tostring() {
return "I'm a vehicle";
}
public void compare(int a,int b){
if(a>b)
System.out.println("a速度大");
else
System.out.println("b速度大");
}
}
//接口类
public interface Comparable {
public void compare(int a,int b) ;
}
有个东西叫ide


就算没有ide,编译下,编译器也会告诉你错误