package com.shrimpking.t3;
/**
* Created by IntelliJ IDEA.
*
* @Author : Shrimpking
* @create 2024/10/8 17:46
*/
class Bell{
public void ring(){
System.out.println("bell ring...");
}
}
class Bicycle2 {
private Bell bell; //聚集关系, 组成部分,
public Bell getBell(){
return this.bell;
}
public void setBell(Bell bell){
this.bell = bell;
}
//发声
public void alert(){
if (bell != null){
bell.ring();
}
}
}
public class BicycleBellTest
{
public static void main(String[] args)
{
Bicycle2 bicycle = new Bicycle2();
bicycle.setBell(new Bell());
bicycle.alert(); //
}
}
BicycleBellTest
最新推荐文章于 2025-01-16 23:49:26 发布
281

被折叠的 条评论
为什么被折叠?



