public interface Car {
int price = 1;
void run();
}
public abstract class AbstractCar {
int price;
public void run(){
System.out.println("hh");
}
abstract void stop();
}
应用场景
An abstract class is good if you think you will plan on using inheritance since it provides a common base class implementation to derived classes.
An abstract class is also good if you want to be able to declare non-public members. In an interface, all methods must be public.
If you think you will need to add methods in the future, then an abstract class is a better choice. Because if you add new method headings to an interface, then all of the classes that already implement that interface will have to be changed to implement the new methods. That can be quite a hassle.
Interfaces are a good choice when you think that the API will not change for a while.
Interfaces are also good when you want to have something similar to multiple inheritance, since you can implement multiple interfaces.