At first compiler checks the availability of exact matching function definition. If it does not find, then checks for other possible implementations to which the function call can be mapped to. In the first two examples, it finds the exact match so it does not give any error and runs fine. In the last scenario it sees that there is no definition of function and as an alternative this call can be fulfilled through the other two functions..
This is where the ambiguity comes and compiler gives compilation error.
You can see the same thing happening if you call the function using int argument . like in below code
it would give compilation error at given two line of codes
It is not about static of instance methods but about the ambiguity that it faces while uniqualy identifying which function to call. if you make then instance methods even then you would get the same compilation error like in below code snippet.
you will get the compilation error on the same lines which are -
I hope this would clear your doubt.
Joined: Jun 17, 2009
Ankit Garg wrote:This has been asked multiple times before. Try to search first before asking a question. Here are a few results which contain similar questions
This blog is not only about asking and answering questions. I probably could find the answers to my questions on www.google.com just as easily as www.javaranch.com. The point of asking questions on this blog is to have an on-going conversation with other people who are interested in the Java language. Maybe I could find the answers in a book, but it's more fun to go back and forth with other developers about these questions. I don't want to read a lot of message threads from five years ago looking for the one that answers my question. The learning experience is really a "live" experience here.
The point of asking questions on this blog is to have an on-going conversation with other people who are interested in the Java language. Maybe I could find the answers in a book, but it's more fun to go back and forth with other developers about these questions.
This can go both ways... If the topic is general (and open enough) to get into an interesting conversation, then yes. If the topic is complex enough to discuss the many nuances, then yes.
If the topic is looking for a straight answer (and not an open ended discussion), on a relatively simple topic, or on something that comes up often, then no. Not doing a quick check prior to asking the question is just being lazy, and shows a disregard for other people's time.
These examples are, of course, the two extremes. I am not commenting on where this topic fits.
I don't want to read a lot of message threads from five years ago looking for the one that answers my question. The learning experience is really a "live" experience here.
It may be boring, but reading books, reading tutorials, etc. etc. is part of research, which is an important skill needed by any professional programmer.
Keep in mind that you are asking very simple (classroom) questions to a forum. What will happen when you run into something hard in a real project? Say debugging a huge program that has been around for decades, and worked upon by hundreds of developers (many of which changed jobs) -- there might not be a forum of people that can help you.