Examination of the way the class loader works : class object « Class « Java






Examination of the way the class loader works

Examination of the way the class loader works
 
// : c10:SweetShop.java
// Examination of the way the class loader works.
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.

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");

  }
} ///:~



           
         
  








Related examples in the same category

1.Create Object DemoCreate Object Demo
2.Passing objects to methods may not be what you're used to.Passing objects to methods may not be what you're used to.
3.Demonstrates Reference objectsDemonstrates Reference objects
4.A companion class to modify immutable objectsA companion class to modify immutable objects
5.Objects that cannot be modified are immune to aliasingObjects that cannot be modified are immune to aliasing
6.A changeable wrapper classA changeable wrapper class
7.This program demonstrates object construction
8.This program tests the Employee classThis program tests the Employee class