Reference variable casting

In the following code , in the cast class , i have explicitly type-casted dog reference to Animal type . But still when i invoke , a1.makenoise () , Dog class is invoked , not the Animal class . Can anyone explain the reason please ??

It is calling the method by the Dog since polymorphism plays here. The object type method is being invoked not the reference type.
In your example, the dog masquerading as an animal, when calling the overriden method will surely call the dog version since it is its object type. The reference type animal only restricts the methods and variables, that can be invoked.

In the following code , in the cast class , i have explicitly type-casted dog reference to Animal type . But still when i invoke , a1.makenoise () , Dog class is invoked , not the Animal class . Can anyone explain the reason please ??

A dog IS-A animal meaning if you expect an animal, and someone gives you a dog, it should be okay.

Furthermore, the dog doesn't lose its attributes just because you don't know what type of animal you are holding. If it is a dog, and you expect your animal to make noise, it will bark.

In Kathy Sierra book , it is given that methods marked as final cannot be overridden . But the below code compiles fine and gives the output as clidlet . I am confused . Please let me know the solution to this .

And please stop using the same thread for different questions - start a new thread (after searching to see if someone else has already asked the same question).

The reason it works is that it is not an override, it's just the definition of another method with the same name. You cannot override private methods. The private method in the superclass is not visible to the subclass - how could it possibly be an override?

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