Methods in Java



This content originally appeared on DEV Community and was authored by Jeeva Aj

Method :

  1. Set of instructions for achieving a specific-tasks – with a name (or) with or without arguments (or) with or without return datatype.
  2. If we do not return any value, we should mention “void” before method name.
  3. Modularity
  4. Code Reusability

employee1.enquiry();
employee1.enquiry(1234);
}

private void enquiry(int accNo) {
    System.out.println("Balance enquiry");

}

private void enquiry() {
    System.out.println("General enquiry");

}

Same method name with different number of arguments is called Method overloading.

employee1.enquiry(15.3f);
private void enquiry(float gold) {
System.out.println(“Gold rate please”);
Same method name with different type of arguments is also known as Method overloading.
Another name called Compile time polymorphism.


This content originally appeared on DEV Community and was authored by Jeeva Aj