package week4;
import java.util.HashMap;
//the class is set as final before release for sharing or use,
//so that others cannot overwrite
public final class myClass {
//set the data to be used by others to be private and final so that it cannot be overwritten.
private static HashMap<Integer, String> hm;
//But to allow others to use, need to set as public
public myClass() {
myClass.hm = new HashMap <Integer, String>();
}
public myClass gethm() {
return (myClass) hm.clone();
}
public static void main(String [] args)
{
myClass a = new myClass();
a.gethm();
}
}
/*Exception in thread "main" java.lang.ClassCastException: java.util.HashMap cannot be cast to week4.myClass
at week4.myClass.gethm(myClass.java:18)
at week4.myClass.main(myClass.java:25)
*/