Java_继承入门
public class Computer {
private String cpu;
private int memory;
private int disk;
public Computer(String cpu, int memory, int disk) {
this.cpu = cpu;
this.memory = memory;
this.disk = disk;
}
public String getDetails() {
return "cpu=" + cpu + " memory=" + memory + " disk=" + disk;
}
public String getCpu() {
return cpu;
}
public void setCpu(String cpu) {
this.cpu = cpu;
}
public int getMemory() {
return memory;
}
public void setMemory(int memory) {
this.memory = memory;
}
public int getDisk() {
return disk;
}
public void setDisk(int disk) {
this.disk = disk;
}
}
public class Pc extends Computer {
private String brand;
public Pc(String cpu, int memory, int disk, String brand) {
super(cpu, memory, disk);
this.brand = brand;
}
public void showInfo() {
System.out.println("Pc信息为"+getDetails()+" brand="+brand);
}
}
public class Test {
public static void main(String[] args) {
Pc pc = new Pc(" Amd",16,512,"LEGION");
pc.showInfo();
}
}