Method Binding
• Objects are used to call methods.
• Method Binding is an object that can be used to call an arbitrary public method, on an instance that is acquired by evaluating the leading portion of a method binding expression via a value binding.
• It is legal for a class to have two or more methods with the same name.
• Java has to be able to uniquely associate the invocation of a method with its definition relying on the number and types of arguments.
• Therefore the same-named methods must be distinguished:
1) by the number of arguments, or
2) by the types of arguments
• Overloading and inheritance are two ways to implement
polymorphism.
Method Overriding.
- There may be some occasions when we want an object to respond to the same method but have different behavior when that method is called.
- That means, we should override the method defined in the super class. This is possible by defining a method in a sub class that has the same name, same arguments and same return type as a method in the super class.
- Then when that method is called, the method defined in the sub class is invoked and executed instead of the one in the super class. This is known as overriding.