1.

Which among the following is the best situation to use upcasting?(a) For general code dealing with only subtype(b) For general code dealing with only supertype(c) For general code dealing with both the supertype and subtype(d) For writing a rigid code with respect to subtypeThe question was posed to me in an interview for job.This is a very interesting question from Upcasting in section Default Arguments vs Overloading, Upcasting and Downcasting of Object Oriented Programming

Answer»

Right answer is (b) For general code DEALING with only supertype

Best explanation: When a general code has to be written where we USE only the supertype object or the data of bigger size, then upcasting would be the best OPTION. Since the WHOLE code will require only the supertype name references.



Discussion

No Comment Found

Related InterviewSolutions