1.

Can reference to an object be returned from a method?(a) Yes, always possible(b) Yes, but not always(c) No, never possible(d) No, Not possible because referred element would be destroyedThe question was asked during an internship interview.My question comes from Object Reference topic in division Object of Object Oriented Programming

Answer»

The correct option is (b) Yes, but not always

Easy explanation - This is possible but not always, since the reference being RETURNED may get DESTROYED with the return of method. This is an UNDESIRABLE condition, HENCE it is not always possible to return REFERENCES. But it is always possible if the referred element is not local to the method.



Discussion

No Comment Found

Related InterviewSolutions