3 回答
TA贡献1827条经验 获得超7个赞
我依靠 这具体上课来做我的工作
我依靠 任何类别那确实是 这东西做我的工作。
TA贡献1864条经验 获得超2个赞
class Car implements IDrivable
基本例子:
interface IDrivable { void accelerate(); void brake(); }
class Car implements IDrivable { void accelerate() { System.out.println("Vroom"); } void brake() { System.out.println("Queeeeek");}}
class Bike implements IDrivable { void accelerate() { System.out.println("Rattle, Rattle, ..."); } void brake() { System.out.println("..."); }}
List<IDrivable> vehicleList = new ArrayList<IDrivable>();list.add(new Car());list.add(new Car());list.add(new Bike());list.add(new Car());list.add(new Bike());list.add(new Bike());
accelerate()
:
for(IDrivable vehicle: vehicleList) { vehicle.accelerate(); //this could be a bike or a car, or anything that implements IDrivable}
TA贡献1821条经验 获得超4个赞
java.sql.Connection
Connection
Connection
java.util.Collection
size
, add
remove
public float calculateCoefficient(Collection collection) { return collection.size() * something / somethingElse;}
LinkedList
TreeSet
.
LinkedList
TreeSet
Collection
size()
Collection
LinkedList
TreeSet
添加回答
举报