A Thinking in Java program is as follows:
package typeinfo;
import static util.Print.*;
class Candy {
static { print(\"Loading Candy\"); }
}
class Gum {
Your classes are in the package typeinfo
, so their fully-qualified names are typeinfo.Gum
, typeinfo.Candy
and typeinfo.Cookie
. Class.forName() only accepts fully-qualified names:
Parameters:
className
- the fully qualified name of the desired class.
Change your code to:
try {
Class.forName("typeinfo.Gum");
} catch(ClassNotFoundException e) {
print("Couldn't find Gum");
}