/* * File: ReferenceCall.java * Author: Java, Java, Java * Description: This application illustrates what happens when * a parameter of a reference type (CyberPet) is modified within * a method. For reference types (as opposed to primitive types) * any changes to the parameter take effect in the object that the * parameter refers to, and so will persist after the method is done. * In this case pet's name will change from "Harry" to "Mary" as * a result of calling the myMethod(pet) in main(). The output * received will be: main: pet name is Harry myMethod: pet name is Harry myMethod: pet name is Mary main: pet name is Mary */ public class ReferenceCall { public static void myMethod(CyberPet p) { System.out.println("myMethod: pet name is " + p.getName()); p.setName("Mary"); System.out.println("myMethod: pet name is " + p.getName()); } // myMethod() public static void main(String argv[]) { CyberPet pet = new CyberPet(); pet.setName("Harry"); System.out.println("main: pet name is " + pet.getName()); myMethod(pet); System.out.println("main: pet name is " + pet.getName()); }// main() } // ReferenceCall