代码:
package com.by.bridge;
interface color {
String getColor();
}
class red implements color{
@Override
public String getColor() {
// TODO Auto-generated method stub
return "red";
}
}
class yellow implements color {
@Override
public String getColor() {
// TODO Auto-generated method stub
return "yellow";
}
}
abstract class brash{
public abstract void paint();
color color;
public color getColor() {
return color;
}
public void setColor(color color) {
this.color = color;
}
}
class BigBrash extends brash{
@Override
public void paint() {
System.out.println("使用字号为24px毛笔,颜色为:"+color.getColor());
}
}
class SmallBrash extends brash{
@Override
public void paint() {
System.out.println("使用字号为12px毛笔,颜色为:"+color.getColor());
}
}
public class Test {
public static void main(String[] args) {
brash brash=new BigBrash();
brash.setColor(new red());
brash.paint();
}
}
结果:
标签:brash,桥接,getColor,void,class,--,设计模式,public,color From: https://www.cnblogs.com/123-456-789/p/16814569.html