Java Interface

example

public interface Car {
	public int getSpeed();
	public boolean accelerate();
}
public class Avante implements Car {
	int speed;

	@Override
	public int getSpeed() {
		return speed;
	}

	@Override
	public boolean accelerate() {
		speed += 10;
		return false;
	}

}
public class Matiz implements Car {
	int speed;

	@Override
	public int getSpeed() {
		return speed;
	}

	@Override
	public boolean accelerate() {
		speed += 20;
		return false;
	}

}
public class Drive {
	public static void main(String[] args) {
		Car avante = new Avante();
		Car matiz = new Matiz();

		drive(avante, "Avante");
		drive(matiz, "Matiz");
	}

	private static void drive(Car car, String name) {
		System.out.println(name);
		for (int i = 0; i < 10; i++) {
			car.accelerate();
			System.out.println(i + ":" + car.getSpeed());
		}
	}
}
What Else?
inflearn react api server -50% 할인쿠폰: 15108-f2af1e086101 buy me a coffee