professor kevin molloy adapted from slides originally
play

Professor: Kevin Molloy (adapted from slides originally developed by - PowerPoint PPT Presentation

Professor: Kevin Molloy (adapted from slides originally developed by Alvin Chao) A reference is a variable that refers so something else and can be used as an alias for that something else. You have already used a reference (Scanner and


  1. Professor: Kevin Molloy (adapted from slides originally developed by Alvin Chao)

  2. • A reference is a variable that refers so something else and can be used as an alias for that something else. • You have already used a reference (Scanner and String are examples types that are references). • In general, anything that is not one of the primitive types is a reference.

  3. What are the reference types in the example above? • What is the difference between primitive and reference type names? • Variables in Java can use at most eight bytes of memory. The values "Beyonce" • and System.in cannot be stored directly in the memory locations for name and in. What is the value of the variable count? What is the value of the variable price? •

  4. • What is the value of the variable name ? • What is the value of the variable in ? • Carefully explain what it means to assign one variable to another. For example, what does the statement price = count; do in terms of memory?

  5. Draw a memory diagram for the following code. What is the output of the following statements after int width; running the code above? double score; Explain your answer using the Scanner input; diagram. String first; String other; What happens if we run the width = 20; following (express in our score = 0.94; memory diagram and the input = new Scanner(System.in); output): first = "Taylor"; first = "Swift"; score = width; other = first; System.out.println(other);

  6. Draw a memory diagram for the following code. What is the output of the following statements after int width; running the code above? double score; Explain your answer using the Scanner input; diagram. String first; String other; What happens if we run the width = 20; following (express in our score = 0.94; memory diagram and the input = new Scanner(System.in); output): first = "Taylor"; first = "Swift"; score = width; other = first; System.out.println(other);

  7. • Acknowledgements • Parts of this activity are based on materials developed by Helen Hu and Urik Halliday, modified by Chris Mayfield and Nathan Sprague, and licensed under CC BY-NC 4.0 International </end>

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend