/** * example1.java - an example of an unchecked (Null Pointer) exception * @author Richard S. Huntrods * @date June 13, 2001 * @version 1.0 * */ public class Example2 { private int myNumerator; private int myDenominator; private int myAnswer; Example2(int myNumerator, int myDenominator) { this.myNumerator = myNumerator; this.myDenominator = myDenominator; this.myAnswer = 0; } public void calculate() throws Exception { myAnswer = myNumerator / myDenominator; System.out.println(myNumerator + " / " + myDenominator + " = " + myAnswer); } public static void main(String[] args) throws Exception { Example2 ex2 = new Example2(5, 0); // here's where we set up 5/0... ex2.calculate(); // here's where we trigger the exception... } }