/* Author: James Tam Version: January 27, 2021 Learning objective: discovering that references are separate from the item (e.g. object, array) being referred to. */ public class Driver { public static void main(String [] args) { //Reference to a person object not //an actual object. Person aPersonReference = null; //Reference to a string not a string. String stringReference = null; //Reference to an 'int' array no array has been created yet. int [] intArrayReference = null; //Runtime error 1: 'crashes' the program because no //object exist yet (constructor hasn't been called). //The following will create a Person object if uncommented. //aPersonReference = new Person("Charlie Sheen"); stringReference = aPersonReference.getName(); //Runtime error 2: No string object exists yet. //Comment out the code for Runtime error 1 and you will //see the program crash when it attempts to call a //String method on a non-existance object. //Either of the following will create String objects //if they are uncommented. // stringReference = "abc"; // stringReference = new String("Hru?"); System.out.println(stringReference.toUpperCase()); //Runtime error 3: No array exists yet. //Comment out the code for Runtime error 2 & 3 and you will //see the program crash when it attempts to access an //element of an non-existance array. //The following will create an integer array if uncommented. //intArrayReference = new int[3]; intArrayReference[2] = 888; } }