Reference Variables QuizS2C Home « Reference Variables Quiz

Java Objects & Classes Quiz 4

The quiz below tests your knowledge of the material learnt in Objects & Classes - Lesson 4 - Reference Variables.

Question 1 : Where are objects stored?
- Objects are stored on the heap.
Question 2 : Where are reference variables stored?
- Reference variables are stored on the stack.
Question 3 : How does the JVM reclaim memory?
- The JVM reclaims memory through garbage collection.
Question 4 : Two ways an object becomes eligible for garbage collection are when it goes out of scope and no live references exist and when all pointers to it are set to null. What is the third?
- An object becomes eligible for garbage collection when the object is unreachable.
Question 5 : How can we check the reference type of an object?
- We can check the reference type using the <code>instanceof</code> operator.
Question 6 : What is output from the following code snippet?

public class Testinstanceof {
    public static void main (String[] args) {
        String moggy = new String();
        Cat string = new Cat();
        if (string instanceof String) { // Check for Cat instance
            System.out.println("string is a String.");
        }
    }
}
- You will get a compiler error for <i>inconvertible types</em>.
Question 7 : A reference variable holds an objects state?
- false - A reference variable holds a pointer to an object on the heap.
Quiz Progress Bar Please select an answer


What's Next?

The next quiz tests your knowledge on the basics of Java methods.