This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
The output is going to be 2. The reason is that polymorphism means - dynamically figure out which method to call based on the actual instance type. So we start out with a new F. This is an F. It is marked as an F internally with a special marker.
Now we assign this to a D reference. This is fine- object references can point to the subclass or any base class. However, the object itself is an F. Later we could say ref1 = new D(); and that would be valid as well.
Now we tell it- we have another reference, this one is called ref2, and it points to something of type E. We assign it to the original object F. This is fine as well- the F is a subclass of E.
Now finally, we ask to call the function on ref2. It is pointing to the object of type F. It dynamically resolves this, and says- what is the function for F? The one that returns 2.
It returns 2.
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com
subject: I don't understand the result of this question, could somebody please explain me?