今天学了什么
学习了接口,完成了综合实例的练习
接口:
package interfacedemo;
public interface Car {
public String getName();
public String getColor();
public double getPrice();
}
BMW类:
package interfacedemo;
public class BMW implements Car {
@Override
public String getName() {
String name = "宝马";
return name;
}
@Override
public String getColor() {
String color = "红色";
return color;
}
@Override
public double getPrice() {
double price = 8000000;
return price;
}
public static void main(String[] args) {
Car car = new BMW();
String name = car.getName();
String color = car.getColor();
double price = car.getPrice();
System.out.println("价值"+price+"元的"+color+name);
}
}
运行截图:
明天计划
练习使用接口