I Have one basic Question,sometime we have to override java API Jar class method for change in implementation,My question is how these overridden method is getting called by API Classes.How API knows new class name which has overridden the method?
Asked
Active
Viewed 948 times
-3
-
Go thru this post it may answer your question http://stackoverflow.com/questions/1543191/method-overriding-in-java – mhasan Sep 25 '16 at 08:19
2 Answers
0
Basically the byte code generated for the class has got the byte code for your overridden method. So when you create an object of child type. JVM will go up in the hierarchy to check the definition of the method while it executes the code. If it finds in the child class first, that definition of method will be executed else it will go to the parent class.
For a little detail :you can read in the book: Programming for the Java Virtual Machine

Shweta Gulati
- 566
- 1
- 7
- 17
0
In simple language , when you are overriding a method for implementation and when the method is invoked ,JVM will look at the object type calling the method and will search for the method in that class.In case the method is not found then it will execute the method defined in the superclass.

Shivam Jari
- 101
- 11