package study3_day05;
/**
*
* 车的泛类型模拟Demo
*
* 定义一个多选项的类
* 包含了车的价格和名称,进行了封装。
*
*/
public class Car<Name,Price> {
private Name n;
private Price p;
public void setName(Name n){
this.n = n;
}
public void setPrice(Price P){
this.p=p;
}
public Name getName() {
return n;
}
public Price getPrice() {
return p;
}
}
package study3_day05;
public class CarDemo {
public static void main(String[] args){
Car<String, String> car=new Car<String, String>();
car.setPrice("10000");
car.setName("宝马");
System.out.println(car.getName());
System.out.println(car.getPrice());
}
}