DEV Community

Jeeva Aj
Jeeva Aj

Posted on

Methods in Java

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");

}
Enter fullscreen mode Exit fullscreen mode

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.

Top comments (0)