package com.itheima.other; import org.junit.Test; public class WrapperTest { @Test public void fun01(){ Qq qq = new Qq(); // qq.run(); // qq.stop(); Car car = new WraperCar(qq); car.run(); car.stop(); } interface Car{ void run(); void stop(); } class Qq implements Car{ @Override public void run() { System.out.println("跑60迈..."); } @Override public void stop() { System.out.println("刹车...."); } } class WraperCar implements Car{ Car car; public WraperCar(Car car) { this.car = car; } //改速度 @Override public void run() { System.out.println("加了鸡血,跑100迈..."); } //刹车不改 @Override public void stop() { car.stop(); } } }
时间: 2024-10-14 06:58:01