java49-方法重载

定义一个computer类
public class computer {
public void runSoftWor(vidio vedio){
System.out.println("视频长度是 "+vedio.getLength());
}

public void runSoftWor(Voice voice){
    System.out.println("歌曲的名字是 "+voice.getTitle());
}

public boolean runSoftWor(vidio vedio,long maxLength){

    System.out.println("视频长度是 "+vedio.getLength());
    return true;
}

}
定义一个vidio类
public class vidio {
private long length;

public long getLength() {
    return length;
}

public void setLength(long length) {
    this.length = length;
}

}
定义一个voice类
public class Voice {
private String title;

public String getTitle() {
    return title;
}

public void setTitle(String title) {
    this.title = title;
}

}
定义一个测试方法重载的类
public class test15 {
public static void main(String[] args) {

    computer com = new computer();
    vidio vedio = new vidio();
    vedio.setLength(999999L);
    com.runSoftWor(vedio);
    Voice voice = new Voice();
    voice.setTitle("我的中国心");
    com.runSoftWor(voice);
}

}

posted @   前端导师歌谣  阅读(18)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
点击右上角即可分享
微信分享提示