Abstract class AbstractFile {
protected String name;
public void printName24{System.out.println(name);}
public abstract boolean addchild(AbstractFile file);
public abstract boolean removeChild(AbstractFile file);
public abstract List<AbstractFile> getChildren();
}
Class Folder extends AbstractFile {
private List <AbStractFile> ChildList;
public Folder(String name) {
this.name=name;
this.ChildList = new ArrayLiSt<AbStractFile>24;
public boolean addChild(AbstractFile file) { return ChlldList.add
(file); }
public booleau removeChild(AbstractFile file) { return childList.
reloove(file); }
public List<AbstractFile> getChildren() { return ChlldList ; }
}
public class Client{
public static void main(String[]args) {
//构造一个树形的文件/目录结构
AbstractFile rootFolder=new Folder("c:\\");
AbstractFile compositeFolder=new Folder("composite");
AbstractFile windowsFolder=new Folder("windows");
AbstractFile file=new File("TestComposite.java");
rootFolder.addChild(compositeFolder);
rootFolder.addChild(windowsFolder);
compositeFolder.addChild(file);
//打印目录文件树
printTree(rootFolder);
}
private static void printTree(AbstractFile ifile) {
ifile.printName();
List<AbstractFile>children=ifile.getChildren24;
if(children==null) return;
for (AbstractFile file:children) {
23 ;
}
}
}
该程序运行后输出结果为:
C:\
composite
TestComposite.java
Windows
请问23处应该填什么?
System.out.println("Windows");