18 Lecture
CS301
Midterm & Final Term Short Notes
Reference Variables
Reference variables in Java are variables that hold the memory address of an object, rather than the object's value. Multiple reference variables can refer to the same object, allowing for shared access to data. Java's garbage collector automati
Important Mcq's
Midterm & Finalterm Prepration
Past papers included
Download PDF
What is a reference variable in Java? a. A variable that holds the actual value of a data type. b. A variable that holds the memory address of an object. c. A variable that holds both the value of a data type and the memory address of an object. Answer: b
What is the default value of a reference variable in Java? a. 0 b. false c. null Answer: c
Can a reference variable be reassigned to a different object in Java? a. Yes b. No c. It depends on the data type of the reference variable. Answer: a
How does Java handle passing a reference variable as a parameter to a method? a. It passes the actual value of the reference variable. b. It passes the memory address of the object held by the reference variable. c. It does not allow passing reference variables as parameters to methods. Answer: b
Can a reference variable be used to access static methods in Java? a. Yes b. No c. It depends on the access modifier of the static method. Answer: a
How does Java handle garbage collection for objects referenced by reference variables? a. It automatically frees up memory allocated to objects that are no longer being referenced. b. It requires manual intervention to free up memory allocated to objects. c. It does not perform garbage collection for objects referenced by reference variables. Answer: a
What is the difference between an instance variable and a reference variable in Java? a. An instance variable holds the memory address of an object, while a reference variable is a variable declared in a class. b. An instance variable is a variable declared in a method, while a reference variable is a variable declared in a class. c. An instance variable is a variable declared in a class, while a reference variable is a variable declared in a method or block that holds a reference to an object. Answer: c
Can a reference variable be used to access private members of a class in Java? a. Yes b. No c. It depends on the access modifier of the private member. Answer: b
How can we check if a reference variable is null in Java? a. By using the null keyword. b. By using the equals() method. c. By using the == operator. Answer: c
Can a reference variable be assigned to a primitive value in Java? a. Yes b. No c. It depends on the data type of the reference variable. Answer: b
Subjective Short Notes
Midterm & Finalterm Prepration
Past papers included
Download PDF
What is a reference variable in Java? Answer: A reference variable is a variable that holds the memory address of an object in Java.
Can multiple reference variables refer to the same object in Java? Answer: Yes, multiple reference variables can refer to the same object in Java.
What is the default value of a reference variable in Java? Answer: The default value of a reference variable in Java is null.
How does Java handle garbage collection for objects referenced by reference variables? Answer: Java's garbage collector automatically frees up memory allocated to objects that are no longer being referenced by any reference variable.
Can a reference variable be null in Java? Answer: Yes, a reference variable can be null in Java.
Can a reference variable be reassigned to a different object in Java? Answer: Yes, a reference variable can be reassigned to a different object in Java.
Can a reference variable be used to access static methods in Java? Answer: Yes, a reference variable can be used to access static methods in Java.
What is the difference between a reference variable and a primitive variable in Java? Answer: A reference variable holds the memory address of an object, while a primitive variable holds the actual value of a data type.
Can a reference variable be used to access private members of a class in Java? Answer: No, a reference variable cannot be used to access private members of a class in Java.
How can we check if a reference variable is null in Java? Answer: We can use the == operator to check if a reference variable is null in Java.