In Java, which of the following statements about reference types are correct:They contain the value of the object that they refer to.A reference can be assigned to another object of the same type.A reference can be assigned to a new object by using the new keyword.They throw a compiler error if you attempt to assign them null.1, 2, and 31, 2, and 42 and 32, 3, and 4
Question
In Java, which of the following statements about reference types are correct:They contain the value of the object that they refer to.A reference can be assigned to another object of the same type.A reference can be assigned to a new object by using the new keyword.They throw a compiler error if you attempt to assign them null.1, 2, and 31, 2, and 42 and 32, 3, and 4
Solution
The correct answer is 2, 3, and 4.
Here's why:
-
They contain the value of the object that they refer to. - This statement is incorrect. In Java, reference types do not contain the actual value of the object they refer to. Instead, they contain a reference (or an address) to the location in memory where the object is stored.
-
A reference can be assigned to another object of the same type. - This statement is correct. In Java, you can assign a reference to another object of the same type.
-
A reference can be assigned to a new object by using the new keyword. - This statement is correct. In Java, you can use the new keyword to create a new object and assign its reference to a reference variable.
-
They throw a compiler error if you attempt to assign them null. - This statement is incorrect. In Java, you can assign null to a reference variable. It does not throw a compiler error. Instead, it means that the reference variable is not referring to any object.
Similar Questions
Which of the following statements is correct? Please select all that apply. Group of answer choicesA reference variable references to an object.A data field in a class must be of a primitive type.A reference variable is an object.A data field in a class should be an instance type.
Which of the following statements is false? Please select all that apply.Group of answer choicesSince addresses are integers, we can assign an int value to a reference variable.A variable of a reference type holds a reference to where an object is stored in the memory.A variable of a primitive type holds a value of the primitive type.Local variables do not have default values.
A(n) ____________________ is another way to refer to an object reference variable. A. primitive variable B. pointer C. referer D. instantiated object E. stack collection
In Java, the declaration of the following code results in __________.public static void main(String[] args) { … Car car; …}1 pointA Car object with unknown stateA Car reference with an undefined valueA Car reference with a null value
Consider the following Java statements. Scanner input = new Scanner(System.in); float radius = input.nextFloat(); double area; Which of the variables in this piece of code are reference variables?
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.