RU beehive logo ITEC dept promo banner
ITEC 120
2012fall
dbraffitt
ibarland

homeinfolectslabsexamshws
tutor/PIsbreeze (snow day)
Object120 + its docsjava.lang docsjava.util docs

lect08b
Memory diagrams, continued
aliasing and mutation; pass-by-value


What `equals` means: If you don't do anything to say otherwise, your own classes have a equals (inherited from java.lang.Object) which just does the same thing == does (?!):
  // Inside class java.lang.Object, deep in the bowels of Java:
  public boolean equals(Object that) { return this == that; }
If you want equals to do something smarter, you have to write it yourself (“overriding the version inherited from Object”). That's what class String does, which is why equals works for Strings.

We will draw pictures for the following:

  int n = 7;
  int k = n;
  
  Song s1 = new Song(...);
  Song s2 = s1;
  Song s3 = new Song(...);

  assigning( n, s2 );
where we have the function:
  static void assigning( int z, Song lalala ) {
    lalala.artist = "Justin Bieber";  // I am *not* assigning to a local variable!  Others referring to object can see changes.
    z = z+1;                          // assigning to my local variable -- nobody else can see changes.
    lalala = new Song(...)            // assigning to my local variable -- nobody else can see changes.
    }

homeinfolectslabsexamshws
tutor/PIsbreeze (snow day)
Object120 + its docsjava.lang docsjava.util docs


©2012, Ian Barland, Radford University
Last modified 2012.Oct.17 (Wed)
Please mail any suggestions
(incl. typos, broken links)
to ibarlandradford.edu
Powered by PLT Scheme