以下代码仅作参考
public class Computer {
public static void main(String[] args) {
Mainboad mainboad = new Mainboad();
mainboad.cpu.work();
mainboad.videoCard.Display();
System.out.println("CPU IS " + mainboad.cpu.getName());
System.out.println("VideoCard IS " + mainboad.videoCard.getName());
}
}
class GalaxyVideoCard implements VideoCard {
String name;
public GalaxyVideoCard(String name) {
super();
this.name = name;
}
@Override
public void Display() {
System.out.println("显卡开始工作");
}
@Override
public String getName() {
return name;
}
}
interface VideoCard {
void Display();
String getName();
}
interface CPU {
void work();
String getName();
}
class IntelCPU implements CPU {
String name;
public IntelCPU(String name) {
super();
this.name = name;
}
@Override
public void work() {
System.out.println("CPU开始工作");
}
@Override
public String getName() {
return name;
}
}
class Mainboad {
CPU cpu;
VideoCard videoCard;
public Mainboad() {
cpu = new IntelCPU("I7 4790k");
videoCard = new GalaxyVideoCard("GTX 980Ti");
}
}
问题的描述中,写得很清楚,照着写方法就是了。。。。