if you are holding an object of the subclass in a reference variable of type superclass?
asked by (58.6k points)

1 Answer

You can call a method of the subclass by first casting the object hold by reference variable of  superclass into the subclass. Once you hold the object in subclass reference type, you can call methods from the subclass. See how type casting works in Java for more details.


That's all about some good interview questions based OOP concept,  Inheritance. You should also know that how private and final variables affect Inheritance. How can you extend a class which is holding a private variable, and probably the difference between private and protected modifier in Java? They are really important to understand and use Inheritance in Java.

Also, if you think we have missed any important question related to Inheritance o If you come across any good questions based upon Inheritance or other object oriented concept then please share with us.
answered by (58.6k points)

Java Interview Questions and Answers 2018

...