In java, I know that we have some differences between static binding and dynamic binding and method overloading is the best example of static binding but I don’t know why it is the method overloading instead of the the method overriding?
Advertisement
Answer
Method overloading is determined at compile time. The compiler decides, based on the compile time type of the parameters passed to a method call, which method having the given name should be invoked. Hence the static binding.
Method overriding is determined by the runtime type of an object. At runtime, the method that gets executed can be a method of some sub-class that wasn’t even written when the code that makes the call was compiled. Hence the dynamic binding.