Hi Rahul, well, it all depends on the parameters you are sending. If you have different methods with the same name, but each one receives different types of parameters, that will make the difference. In your class, first you're sending two integers as parameters to the method meth
so, the chosen method will be the one that receives two parameters type integer. All the other calls to the method meth that you did, you were sending doubles (at least one double), so the chosen method, will be the one that receives parameters type double.
Hope this help, but if I only confuse you more , let me know
Fairy tales are more than true: not because they tell us that dragons exist, but because they tell us that dragons can be beaten. – G.K. Chesterton
If your calling a method with some arguments, first JVM will look for that method and execute them, in-case of overloaded method JVM will look for the argument type say d.meth(5,2.6) ---> (int, double) now the compiler type casts the int value to double in order to fit to the available methods [ explicit type casting is done by default ] so your getting the below mentioned output.
Joined: Mar 20, 2009
Thanks for your replies.Well, I want to prepare for SCJP 1.6.Can any of you recommend any books,mock tests etc. to prepare for the exam?
It's really simple to understand how the JVM decides which overloaded method to choose, as you see in the Java™ Language Specification. Spend a week readign that section and you will understand everything
Now you know to be very careful when overloading.
Joined: Oct 13, 2005
About the SCJP books: I think I ought to move this thread tothe SCJP forum.
rahul lahiri wrote:Thanks for your replies.Well, I want to prepare for SCJP 1.6.Can any of you recommend any books,mock tests etc. to prepare for the exam?
Hi Rahul, good luck with the preparations!
Start with Kathy Sierra & Bert Bates book "SCJP6 study guide"
Read it cover to cover 2-3 times, practice all the examples, do all the questions at end of each chapter.
code with various permutations and combinations! Change something here and there and see how the outcome differs and find out why it behaves that way!
Finally take the Master exams along with book!
Try Devaka's "Exam Lab" FREE . It has 5 mock exams and use it as a learning tool
Go for Enthuware JQ Plus , it is only $28 and there are 13 full mock exams and do as much as you can!
And then go for the Grand Finale!
ps: In addition to the above, be an active rancher! Post your questions here, Help others and share your knowledge and expertise.
It is a give and take policy here!