Passing objects to methods may not be what you're used to. : class object « Class « Java






Passing objects to methods may not be what you're used to.

Passing objects to methods may not be what you're used to.
 
//: c03:PassObject.java
// From 'Thinking in Java, 3rd ed.' (c) Bruce Eckel 2002
// www.BruceEckel.com. See copyright notice in CopyRight.txt.
class Letter {
  char c;
}

public class PassObject {
  static void f(Letter y) {
    y.c = 'z';
  }
  public static void main(String[] args) {
    Letter x = new Letter();
    x.c = 'a';
    System.out.println("1: x.c: " + x.c);
    f(x);
    System.out.println("2: x.c: " + x.c);
  }
} ///:~



           
         
  








Related examples in the same category

1.Create Object DemoCreate Object Demo
2.Demonstrates Reference objectsDemonstrates Reference objects
3.A companion class to modify immutable objectsA companion class to modify immutable objects
4.Objects that cannot be modified are immune to aliasingObjects that cannot be modified are immune to aliasing
5.Examination of the way the class loader worksExamination of the way the class loader works
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