For the first part of the question, you have a parent reference variable holding a child object, then calling a method defined in the Parent class and overridden in the child. Selection of overridden methods is according to the type of object actually held in the reference variable (runtime type). Since the parent reference variable actually holds a child object, the child's version of the method runs. And it prints out the proper message as it's legal to pass a generic List to a non-generic List.
As for the second part of the question, I think it compiles. why don't you try compiling it?
Hey Ken, for the first part, c is a parent a reference. So the compiler is trying to access the say() of Parent, and since the types don't match it gives an error, Isn't it? [ November 10, 2008: Message edited by: Maleen Abeydeera ]
Originally posted by Ken Truitt: As for the second part of the question, I think it compiles. why don't you try compiling it?
Are you sure the second part Compiles?
Joined: Sep 22, 2008
I had tried to compile it. It does not compile. Actually, I want to know whether such questions will be asked and if so, could anyone please send me the link of related tutorials as questions related to overriding/overloading with respect to generics are not there in KS & BB.