package HspLearningExtend;
public class PC extends ExerciseComputer {
private String brand;
//根据继承的规则,自动吧构造器的调用写好
//体现了继承设计的基本思想,父类的构造器完成父类属性初始化
//子类的构造器完成子类的属性初始化
public PC(String cpu, int memory, int disk, String brand) {
super(cpu, memory, disk);
this.brand = brand;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public void printInfo() {
System.out.println("PC的信息如下");
// System.out.println(getCpu()+getMemory()+getDisk());
//调用父类的getDetails
System.out.println(getDetials() + " brand" + brand);
}
}
package HspLearningExtend;
public class PC extends ExerciseComputer {
private String brand;
//根据继承的规则,自动吧构造器的调用写好
//体现了继承设计的基本思想,父类的构造器完成父类属性初始化
//子类的构造器完成子类的属性初始化
public PC(String cpu, int memory, int disk, String brand) {
super(cpu, memory, disk);
this.brand = brand;
}
public String getBrand() {
return brand;
}
public void setBrand(String brand) {
this.brand = brand;
}
public void printInfo() {
System.out.println("PC的信息如下");
// System.out.println(getCpu()+getMemory()+getDisk());
//调用父类的getDetails
System.out.println(getDetials() + " brand" + brand);
}
}
package HspLearningExtend;
public class Computer02 {
public static void main(String[] args) {
PC pc = new PC(" Intel",16,500," IBM");
pc.printInfo();
}
}
网友评论