<think in Java > example code for this book.
Package com.yuan.test;//: typeinfo/sweetshop.java//examination of the way the class loader works.class candy {static {system.out.println ("Loading Candy" );}} Class gum {static {system.out.println ("Loading gum");}} Class cookie {static {system.out.println ("Loading cookie");}} Public class sweetshop {public static void main (String[] args) { System.out.println ("Inside main"); New candy (); System.out.println ("After creating candy"); Try {class.forname ("Gum");} catch (classnotfoundexception e) {system.out.println ("couldn ' T find gum");} System.out.println ("After class.forname (\" gum\ ")"); New cookie (); System.out.println ("After creating cookie");}} Output result inside mainloading candyafter creating candycouldn ' t find gumafter Class.forName ("Gum") loading cOokieafter creating cookie
Java Class.forName ()