Upgrade to Pro — share decks privately, control downloads, hide ads and more …

CSE110 Lecture 24

CSE110 Lecture 24

Principles of Programming with Java
References
(202006)

Tweet

More Decks by Javier Gonzalez-Sanchez

Other Decks in Programming

Transcript

  1. CSE110 Principles of Programming with Java Lecture 24: References Javier

    Gonzalez-Sanchez [email protected] javiergs.engineering.asu.edu | javiergs.com Office Hours: By appointment
  2. Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 3 Assignment

    | Primitive Types • The act of assignment takes a copy of a value and stores it in a variable • For primitive types:
  3. Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 4 References

    • An object reference variable holds the memory address of an object • Rather than dealing with arbitrary addresses, we often depict a reference graphically as a “pointer” to an object • For object references, assignment copies the memory location: jane john jane john
  4. Javier Gonzalez-Sanchez | CSE110 | Summer 2020 | 9 Arrays

    of Objects • The elements of an array can be object references. • Suppose that we have the Student class Student[] list = new Student[5]; //The following causes NullPointerException int id = list[0].getID(); //We need to instantiate each object first: list[0] = new Student(“Bob”); list[1] = new Student(“Mary”); list[2] = new Student(“Peter”); // ... // OR we can use the Initializer: Student[] list = {new Student(“Bob”), new Student(“Mary”), new Student(“Peter”) };
  5. CSE110 - Principles of Programming Javier Gonzalez-Sanchez [email protected] Summer 2020

    Disclaimer. These slides can only be used as study material for the class CSE110 at ASU. They cannot be distributed or used for another purpose.