package reusing;class Cleanser{ private String s="Cleanser"; public void append(String a){ s+=a; } public void dilute(){ append(" dilute()"); } public void apply(){ append(" apply()"); } public void scrub(){ append(" scrub() "); } public String toString(){ return s; } public static void main(String[] args){ Cleanser x=new Cleanser(); x.dilute();x.apply();x.scrub(); System.out.println(x); } } class Detergent extends Cleanser{ public void scrub(){ append(" Detergent.scrub()"); } public void foam(){ append(" foam()"); } } class NewDetergent extends Detergent{ public void scrub(){ append(" NewDetergent.scrub()"); super.scrub(); } public void sterilize(){ append("sub.sterilize()"); } public static void main(String[] args){ NewDetergent nb=new NewDetergent(); nb.dilute(); nb.apply(); nb.scrub(); nb.sterilize(); System.out.println(nb); } }
添加回答
举报
0/150
提交
取消