import java.io.*; public class derive extends base implements Cloneable { public item it; public derive (int m, int n) { super(n); // must be first statement! System.out.print("derive constructor with args: "); System.out.print(m); System.out.print(", "); System.out.println(n); it = new item(m); } public derive() { System.out.println("derive constructor without arg"); it = new item(); // note: in C++, the constr call is automatic } public Object clone() // implements the clone method { System.out.println("derive clone method"); derive d = new derive(); base b = (base)super.clone(); d.size = b.size; d.data_arr = b.data_arr; d.it = (item)it.clone(); return d; } public void print(PrintWriter os) {os.println("write derive obj to stream: "); os.print(" "); super.print(os); os.println(); os.print(" "); it.print(os); } public String toString() { CharArrayWriter buf = new CharArrayWriter(); PrintWriter os = new PrintWriter(buf); print(os); return buf.toString(); } }// end class derive