Machine-translated by Google. Questions are authored in English.
Top

Discussion

In object oriented programming for references and values, which of the following statements are true :

(i) If variables are references, then every object must be created explicitly.
(ii) If variables are values, then object creation can happen implicitly as result.
(iii) If variables are references, then every object must be created implicitly
(iv) If variables are values, then object creation happens explicitly

  • A.(i) and (ii)
  • B.(ii) and (iii)
  • C.(iii) and (iv)
  • D.(i) and (iv)

Answer: A

The true statements are (i) and (ii).

With reference semantics, as in Java, a variable holds only a reference. Declaring it creates no object, so every object must be created explicitly, for example with new (i).

With value semantics, as for C++ objects declared as local variables, the variable is the object itself. Declaring it, passing it by value or returning it creates an object implicitly (ii).

Statements (iii) and (iv) reverse these two rules, so every option including them is wrong.

No comment is present. Be the first to comment.
Loading…

Post your comment

Please log in or register to post a comment.