mendez.joseph18
mendez.joseph18 1d ago • 10 views

Primitive vs. Reference Data Types Quiz: AP Computer Science A

Hey there! 👋 Let's solidify your understanding of Primitive vs. Reference Data Types in AP Computer Science A. First, a quick review, then a practice quiz to test your knowledge! 🤓
💻 Computer Science & Technology
🪄

🚀 Can't Find Your Exact Topic?

Let our AI Worksheet Generator create custom study notes, online quizzes, and printable PDFs in seconds. 100% Free!

✨ Generate Custom Content

1 Answers

✅ Best Answer
User Avatar
jessica387 13h ago

📚 Quick Study Guide

  • 🔢 Primitive data types store the actual values directly in memory. Examples include `int`, `double`, `boolean`, and `char`.
  • 🧠 Reference data types store the address (or reference) to the memory location where the data is stored. Objects and arrays are reference types.
  • 🔗 When you assign a primitive variable to another, you're creating a copy of the value.
  • 📦 When you assign a reference variable, you're creating another reference to the same object. Changing the object through one reference will affect all references.
  • == For primitive types, `==` compares the actual values.
  • 📍 For reference types, `==` compares the memory addresses (references), not the actual content of the objects. Use `.equals()` to compare the content of objects.
  • 🗑️ Garbage collection reclaims memory occupied by objects that are no longer referenced.

🧪 Practice Quiz

  1. Which of the following is a primitive data type in Java?
    1. `String`
    2. `ArrayList`
    3. `int`
    4. `Scanner`
  2. What does a reference variable store?
    1. The actual value of the object
    2. The memory address of the object
    3. A copy of the object
    4. The size of the object
  3. What happens when you assign a primitive variable to another primitive variable?
    1. The second variable becomes an alias of the first
    2. A new memory location is allocated for the second variable, and the value is copied
    3. Both variables point to the same memory location
    4. An error occurs
  4. What happens when you assign a reference variable to another reference variable?
    1. A new object is created with the same value
    2. Both variables point to the same object in memory
    3. The first object is copied into the second variable's memory location
    4. An error occurs if the objects are not of the same type
  5. How do you compare the contents of two `String` objects in Java?
    1. Using the `==` operator
    2. Using the `.equals()` method
    3. Using the `.compareTo()` method
    4. By casting them to primitive types
  6. What will be the output of the following code? ```java int x = 5; int y = x; y = 10; System.out.println(x); ```
    1. `5`
    2. `10`
    3. `15`
    4. An error
  7. What will be the output of the following code? ```java Integer a = new Integer(5); Integer b = a; b = 10; System.out.println(a); ```
    1. `5`
    2. `10`
    3. `15`
    4. An error
Click to see Answers
  1. C
  2. B
  3. B
  4. B
  5. B
  6. A
  7. A

Join the discussion

Please log in to post your answer.

Log In

Earn 2 Points for answering. If your answer is selected as the best, you'll get +20 Points! 🚀