面向对象-习题7(音乐播放信息)
写一个方法输出播放音乐的信息
public class Homework {
public static void main(String[] args) {
Music music = new Music("半岛铁盒",520);
music.play();
music.getInfo();
System.out.println(music.getInfo());
}
}
class Music {
String name;
int times;
public Music(String name,int times){
this.name = name;
this.times = times;
}
//播放功能
public void play() {
System.out.println("音乐"+name+"正在播放中....时长为"+times+"秒");
}
//返回本身属性信息
public String getInfo() {
return "音乐"+name+"正在播放中时长为"+times;
}
}