60.1k views
5 votes
When a method's return type is a class, what is actually returned to the calling program? A. An object of that class B. A reference to an object of that class C. Only the values in the object that the method accessed D. Nothing, the return type is strictly for documentation in this situation.

User Voithos
by
5.0k points

1 Answer

2 votes

Answer:

Option (B) A reference to an object of that class

Step-by-step explanation:

  • The method's return type is nothing but a class ( the data type ).
  • The method contains some statements that has to be executed.
  • The method involves returning the reference of an object but not the object itself.
  • The method returns the reference of the object ( address in the memory space of that particular object) created in the memory for accessing.
  • Lets us take this example
    Sum of Two Integers below:


public\, int \,SumofIntegers (int\, a, int\, b)\{sum = a + b ;return\, sum;\}

  • When the above method SumofIntegers is called it is returning sum ( which is referencing to the object of the class int (as a and b are of int type here ))
  • Here sum is a variable but not the object of a class.
  • So, option (A) is false, as it is returning the sum (a reference to the object)
  • Option (C) is false. method returns the reference of the object not just the value. In case of void the value is null.
  • Option (D) is false. Return type is not just for the documentation.
User Pinal Tilva
by
5.3k points