Sorting by

×

Consider this piece of code and try and print the output. Compare the results with your manual computation. If results match then you have it right when it comes to overriding.

Output:

Clearly the JVM looks at the instance type and not the reference type when it comes to overriding. This is very important to understand otherwise we are missing out on how overriding works.

Try guessing the results of similar code snippet below to verify your understanding.

Thanks for reading !! Watch out more blog posts on Java fundamentals !!!

Leave a Reply

Your email address will not be published. Required fields are marked *

Quote of the week

“A man is but a product of his thoughts. What he thinks, he becomes !!!”

~ Mahatma Gandhi