问题描述
publicclassUseChildGrand{publicstaticvoidmain(String[]args){Childcd=newChild(5,3);System.out.println(cd.outputData());System.out.println(cd.outputData(4));Grandchildgd=newGrandchild(8,5,6);System.out.println(gd.outputData());System.out.println(gd.outputData(5));}}interfaceparentsInterFace{publicabstractStringoutputData();}classParentsimplementsparentsInterFace{intpx;Parents(intx){px=x;}publicStringoutputData(){return"Parents:"px;}}classChildextendsParents{intpc;Child(intx,intc){super(x);pc=c;}publicStringoutputData(){return"Child:"+pc;}publicStringoutputData(intn){returnsuper.outputData()+",Child:"+n*(px+pc);}}classGrandchildextendsChild{intpx,pg;Grandchild(intx,intc,intg){super(x,c);px=2*g;pg=g;}publicStringoutputData(){return"Grandchild:"+pg;}publicStringoutputData(intn){returnsuper.outputData()+",Grandchild:"+n*(px+pg);}}您的朋友461530401为这封邮件插入了背景音乐-下载播放播放器加载中...正在发送...此邮件已成功发送。再回一封