- A method is code block that contains a set of programming statements.
- Also called a function
- Purpose: To implement the logic required for specific behaviour or functionality in a class.
Method Overloading
There are a lot of techniques for working with methods. One technique is called method overloading . Method overloading allows us to define methods with the same name and purpose, but different signatures. The first PlaceOrder method defines two parameters, one for the product to order and one for the quantity of that product. This overload adds a delivery by date, and another overload adds delivery instructions. This overload adds a delivery by date, and another overload adds delivery instructions. For method overloading, the name must be the same, and the number and/or type of parameters must be different. The return type is excluded when comparing signature for overloading, so even though this method has the name, it is not a valid overload, because the only difference is the return type. Overloading lets us provide a simple signature for the simple scenarios and more full-featured signatures for more advanced scenarios, making it easier for other cod...
Comments
Post a Comment