A method is a block of code that performs a specific task.
In Java, a method is a set of code that performs a specific task and can be called upon whenever that task is needed. This helps in organizing code and making it reusable. For example, a method to calculate the total price of items in a shopping cart can be reused whenever a user adds or removes items.
Additional Notes
How would you explain a method in a Java interview?