You can use the edit button up at the top of your post...
Also, once you are using an object of type A, it no longer has methods C D because it is an A object. It's like if you did this:
The Object class does not have a concat method, so calling concat on it will cause an error. It doesn't make sense for it to have a concat method because it is no longer a string. However, if you cast 'o' back to a String, it will still hold "ham" and you may then call the concat method.
Hi All, In the following program when i try to compile it,it invokes the function in the sub class but variable from the super class.For the function,we are supercasting the subclass instance to that of superclass.What about the variable?Why is it calling from the superclass and not from sub class?
help me out soon.
Thanks in advance, NaliniReddy.
[ edited to preserve formatting using the [code] and [/code] UBB tags -ds ] [ July 13, 2004: Message edited by: Dirk Schreckmann ]
Darin Naird: Also, once you are using an object of type A, it no longer has methods C D because it is an A object.
This is not quite right. Once an object is created, it will always be the same kind of object (if you create a String, it will always be a String, even if you reference it as an Object).
As you see from the above code, even though you can refer to an object in a different way, this does not change the object's actual class; it's still the same type of object. It's kind of like using different colored lenses to look at something. If you had a red and blue ball, the ball would look different if you looked at it through a filtered lens that would only let blue through than it would with a filtered lens that only let red through. If you used a clear lens, then you'd see all the colors of the ball. Yet all this time, the ball was still the same ball and it really retained all its colors.
This is the same thing that happens when you assign a different kind of reference to an object. You are merely changing the way you see the object, you are not changing the object itself.
Hope this makes sense. [ July 13, 2004: Message edited by: Junilu Lacar ]